Still wouldn't fix it. They're missing the one for main.Originally Posted by citizen
Quzah.
Still wouldn't fix it. They're missing the one for main.Originally Posted by citizen
Quzah.
Hope is the first step on the road to disappointment.
I thought that was it and deleted it but that just made the whole thing much worse and gave more errors.Originally Posted by citizen
Running the most recent post through a beautifier, this is what you have:Following good indentation habits is for the new to help write good code.Code:#include <stdio.h> #include <string.h> int main() { int a; char name[1]; int d=1; printf ("%s","Welcome to Harry's Vending Machine\n"); printf("Enter a value:\n"); scanf("%d",&a); { if ( a >= 1 ) { printf ("\nPress 1 for 7 up\n"); printf ("\nPress 2 for Coca Cola\n"); printf ("\nPress 3 for Pepsi\n"); printf ("\nPress 4 for Bottled Water\n"); printf ("\nPress 5 for Dr. Pepper\n"); scanf ("%d", 5); printf("Thank you for your purchase\n"); printf ("\nEnjoy your refreshing drink and don't forget your change\n"); } else { printf("Please insert correct amount\n"); scanf("%d", &a); }
[edit]FAQ > How do I... (Level 1) > How do I get a number from the user (C)
Last edited by Dave_Sinkula; 05-12-2006 at 05:46 PM.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
do not need dCode:/* aa.c */ #include <stdio.h> #include <string.h> int main() { int a,d ; char name[1]; d=1; printf ("%s","Welcome to Harry's Vending Machine\n"); printf("Enter a value:\n"); printf ("\nPress 1 for 7 up\n"); printf ("\nPress 2 for Coca Cola\n"); printf ("\nPress 3 for Pepsi\n"); printf ("\nPress 4 for Bottled Water\n"); printf ("\nPress 5 for Dr. Pepper\n"); scanf ("%d", &a); if(a >= 1) { printf("Thank you for your purchase\n"); printf ("\nEnjoy your refreshing drink and don't forget your change\n"); } else { printf("Please insert correct amount\n"); scanf("%d", &a); } }
do not need name[]
menu before enter a value
prog not done are you going to do something with each diff selection?
anyway
Code:if (test;) { statement; } else if (test;) {statement;}
Last edited by kryptkat; 05-12-2006 at 06:03 PM.
actually now that everything seems fine because whenever they put in the $1 value it is working perfectly because it takes them to the soda selection and they can select the soda of their choice. The only problem that I have right now is that I need to find out whenever they put in an incorrect about(anything under $1) it will take them to a message "insert correct amount." That's all I need done for right now. Thank you so much for your help I appreciate itOriginally Posted by kryptkat
This is what I have so far if someone can look over my coding and let me know if everything is correct that would be appreciated. However, when I try to compile the code I am getting a syntax error towards the end which I just can't figure out what it might be from.
Code:/* aa.c */ #include <stdio.h> #include <string.h> int main() { int a; char name[1]; printf ("Welcome to Harry's Vending Machine\n"); printf("Enter a value:\n"); { check: if ('a' >=1) scanf('a'==0); printf ("\nPress 1 for 7 up\n"); printf ("\nPress 2 for Coca Cola\n"); printf ("\nPress 3 for Pepsi\n"); printf ("\nPress 4 for Bottled Water\n"); printf ("\nPress 5 for Dr. Pepper\n"); scanf ('a'==0); if('a' >= 1) { printf("Thank you for your purchase\n"); printf ("\nEnjoy your refreshing drink and don't forget your change\n"); } else { printf("Please insert correct amount\n"); while ( a < 1 ); }
Commented. However there are a few more points, such as 'name' never being used, and the variable a being used uninitialized. Things like that. You need to read your chapter on using scanf over again, and learn how it works.Originally Posted by Harryt123
Quzah.
Hope is the first step on the road to disappointment.
build on this simplified code.
Code:/* aa.c */ #include <stdio.h> int main() { int a; printf ("Welcome to Harry's Vending Machine\n"); printf ("\nPress 1 for 7 up\n"); printf ("\nPress 2 for Coca Cola\n"); printf ("\nPress 3 for Pepsi\n"); printf ("\nPress 4 for Bottled Water\n"); printf ("\nPress 5 for Dr. Pepper\n"); printf("Enter a value:\n"); scanf("%d",&a); if(a >= 1) { printf("Thank you for your purchase\n"); printf ("\nEnjoy your refreshing drink \n"); } }