By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 435,583 Members | 3,481 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,583 IT Pros & Developers. It's quick & easy.

# Another vending machine problem. This is only the first part tho

 P: 1 This is the first part of a program for school. am only trying to get the first part working yet but am not having any joy. Any pointers where im gone wrong #include int main(void){ /* int set [5] = {A1, A2, A3, A4, A5};*/ int i; int A=0.90; int B=1.20; int C=1.10; int D=0.75; int E=1.01; int selection; int cost; int payment; int change; int stock; printf(" A B C D E\n "); printf(" Mars Bounty Curly Wurly Toffee Crisp Double Decker\n "); printf(" 2 2 2 2 2\n "); printf(" €0.90 €1.20 €1.10 €0.75 €1.01\n"); printf("Please make your selection from the list above \n"); scanf("%d", &selection); if (selection==A) { printf("You have selected Mars. Please enter how much money you are inputing\n"); scanf("%d",&payment);} if (payment == 0.90) { printf("Please take your selection and thank you for your custom\n");} else if (payment < 0.90){ printf("Please add some more coins \n");} else if (payment > 0.90) { payment - 0.90 == change;} for (stock = 2; stock<2; stock--); { } Jan 5 '19 #1
Share this Question
2 Replies

 Expert 100+ P: 2,400 Please enclose your source code in [CODE/] tags. This preserves your indentation and numbers each line. Expand|Select|Wrap|Line Numbers #include     int main(void){     /* int set [5] = {A1, A2, A3, A4, A5};*/     int i;     int A=0.90;     int B=1.20;     int C=1.10;     int D=0.75;     int E=1.01;     int selection;     int cost;     int payment;     int change;     int stock;       printf(" A B C D E\n ");     printf(" Mars Bounty Curly Wurly Toffee Crisp Double Decker\n ");     printf(" 2 2 2 2 2\n ");     printf(" €0.90 €1.20 €1.10 €0.75 €1.01\n");     printf("Please make your selection from the list above \n");     scanf("%d", &selection);       if (selection==A) {         printf("You have selected Mars. Please enter how much money you are inputing\n");         scanf("%d",&payment);}     if (payment == 0.90) {         printf("Please take your selection and thank you for your custom\n");}      else if (payment < 0.90){         printf("Please add some more coins \n");}     else if (payment > 0.90) {         payment - 0.90 == change;}     for (stock = 2; stock<2; stock--); {         } Jan 17 '19 #2

 Expert 100+ P: 2,400 Line 4. This comment is confusing because there is no set array. Lines 6-10. These variables are declared int but they are assigned floating point values. Line 20. I don't know if "€" can be used in a string constant. Maybe it is ok. Line 22. You input an integer value into an int variable but you prompted the user to enter a floating point value. Probably should change format string and variable type. Line 24. You compare [probably] floating point values for equality. That won't work well. Refer to What Every Computer Scientist Should Know About Floating-Point Arithmetic. Line 26. (same comment as for line 22) Line 27. (same comment as for line 24) Line 32. "payment - 0.90" is an rvalue. It belongs to the right of the equals sign. "==" is a logical operator, you want the assignment operator "=". Line 33. You initialize stock to 2 and then loop while stock is less than 2. 2 is not less than 2 so it won't loop. Line 33. The semicolon terminates the loop so the brackets on lines 33 and 34 are not part of the loop. Looks like the rest of the program (return statement and closing brace) are missing. Jan 17 '19 #3

### Post your reply

Sign in to post your reply or Sign up for a free account.