Hi everybody,
I've just started programming in C and I've run into a problem. The compiler I'm using was distributed by the school and is a piece of work. Something is obviously wrong with it...maybe it's not ANSI compliant or something.
Anyway, I'm trying to figure out if there's a way to read in user input and test to see if it's valid. I'm working with float variables because we're returning currency amounts, but understand that I may have to read the user's input in as a string and then go from there. Problem is, I'm not really sure where to go from there because I don't know if it's possible.
When the value is read in, I need to return a message to the user if the value is incorrect and prompt them to re-enter until they get it right.
Here's my attempt (using pseudocode):
Thanks,
beacon
I've just started programming in C and I've run into a problem. The compiler I'm using was distributed by the school and is a piece of work. Something is obviously wrong with it...maybe it's not ANSI compliant or something.
Anyway, I'm trying to figure out if there's a way to read in user input and test to see if it's valid. I'm working with float variables because we're returning currency amounts, but understand that I may have to read the user's input in as a string and then go from there. Problem is, I'm not really sure where to go from there because I don't know if it's possible.
When the value is read in, I need to return a message to the user if the value is incorrect and prompt them to re-enter until they get it right.
Here's my attempt (using pseudocode):
Code:
float amount = 0.0;
do{
printf("Please enter an amount: ");
scanf("%f", amount);
if (amount != non-numeric character)
return 1;
else
printf("Invalid amount.\n\n");
return 2;
}while(2);
beacon
Comment