I have managed to compile the code correctly, however I would like to make the program to instead ask the user again to enter a number rather than close. How should I go around this?
By the way, sorry if it sounds stupid but what does WRT mean?
I have managed to compile the code correctly, however I would like to make the program to instead ask the user again to enter a number rather than close. How should I go around this?
By the way, sorry if it sounds stupid but what does WRT mean?
Last edited by bonett09; 12-27-2011 at 01:34 PM.
Use a while(condition). Eg, if you initialize numofbees to 0, the condition could be while(numofbees <= 0).
With Regard To. You can find these if you google "acronym WRT" or whatever, I have to do it pretty often too; recently, "TLA"...By the way, sorry if it sounds stupid but what does WRT mean?
O_OOriginally Posted by acronymfinder.com
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Is this the correct placement for the while loop? If so, I have a problem that when I enter a letter an infinite loop prints out 'How many bees would you like to purchase?' and on the other hand if I enter a number an 'Invalid amount...' prints out everytime.
Examples:
How many bees would you like to purchase?
5
Invalid amount, please try again.
That will be $25, confirm? (Y/N)
OR
How many bees would you like to purchase?
0
Invalid amount, please try again.
How many bees would you like to purchase?
5
Invalid amount, please try again.
That will be $25, confirm? (Y/N)
Code:#include<stdio.h> int main() { int numofbees = 0; float price = 5; char query; while(numofbees <= 0){ printf("How many bees would you like to purchase?\n"); (!scanf("%u", &numofbees)); printf("Invalid amount, please try again.\n"); } printf("That will be $%f, confirm? (Y/N)\n", price*numofbees); scanf(" %c", &query); if(query == 'y'|| query == 'Y') { printf("Transaction completed."); } else { printf("Transaction cancelled."); } getchar(); getchar(); return 0; }
Last edited by bonett09; 12-29-2011 at 03:16 AM.