I have two sets of similar Do While codes files, one with stdin scanf function and the other getInt() from cs50 lib. Both files compile in CS50 appliance. I expect the do while works the same but different results outcome.
It suppose to loop if input value greater than 23 but it exit after input of any integer values and prompt "retry" for non integer value.
I wrote another similar code without GetInt() function in CS50 library instead scanf functions to get input for do while loop and it loop when input value greater than 24 and non-integer input show zero '0'. Why this happen? I cannot complete this PSET1 problem if required to used CS50 lib.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Prompt user for keyboard input
// Input type checking done by CS50 lib
// Loop if input value greater than 23
// Default max height
int myHeight = 0;
do
{
printf("Enter the height of half-pyramid: ");
int myHeight = GetInt();
printf("You have entered %d\n",myHeight);
}
while (myHeight>23);
}
#include <stdio.h>
#int main(void)
{
// Prompt user for keyboard input
//
// Loop if input value greater than 23
// Default max height
int myHeight = 0;
do
{
printf("Enter the height of half-pyramid: ");
scanf("%d",&myHeight);
printf("You have entered %d\n",myHeight);
}
while (myHeight>23);
}