473,411 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

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

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 <stdio.h>

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
2 1675
donbock
2,426 Expert 2GB
Please enclose your source code in [CODE/] tags. This preserves your indentation and numbers each line.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3.  int main(void){
  4.     /* int set [5] = {A1, A2, A3, A4, A5};*/
  5.     int i;
  6.     int A=0.90;
  7.     int B=1.20;
  8.     int C=1.10;
  9.     int D=0.75;
  10.     int E=1.01;
  11.     int selection;
  12.     int cost;
  13.     int payment;
  14.     int change;
  15.     int stock;
  16.  
  17.     printf(" A B C D E\n ");
  18.     printf(" Mars Bounty Curly Wurly Toffee Crisp Double Decker\n ");
  19.     printf(" 2 2 2 2 2\n ");
  20.     printf(" €0.90 €1.20 €1.10 €0.75 €1.01\n");
  21.     printf("Please make your selection from the list above \n");
  22.     scanf("%d", &selection);
  23.  
  24.     if (selection==A) {
  25.         printf("You have selected Mars. Please enter how much money you are inputing\n");
  26.         scanf("%d",&payment);}
  27.     if (payment == 0.90) {
  28.         printf("Please take your selection and thank you for your custom\n");} 
  29.     else if (payment < 0.90){
  30.         printf("Please add some more coins \n");}
  31.     else if (payment > 0.90) {
  32.         payment - 0.90 == change;}
  33.     for (stock = 2; stock<2; stock--); {
  34.         }
Jan 17 '19 #2
donbock
2,426 Expert 2GB
  1. Line 4. This comment is confusing because there is no set array.
  2. Lines 6-10. These variables are declared int but they are assigned floating point values.
  3. Line 20. I don't know if "€" can be used in a string constant. Maybe it is ok.
  4. 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.
  5. 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.
  6. Line 26. (same comment as for line 22)
  7. Line 27. (same comment as for line 24)
  8. 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 "=".
  9. 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.
  10. Line 33. The semicolon terminates the loop so the brackets on lines 33 and 34 are not part of the loop.
  11. Looks like the rest of the program (return statement and closing brace) are missing.
Jan 17 '19 #3

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

Similar topics

1
by: pradeepkumar | last post by:
give me the code for vending machine in c++. it has 10 items in a .first display all the items and its cost and its quantityonhand.then ask the customer if he wishes to buy.if yes tell him to select...
0
by: joestevens232 | last post by:
I am seriously stuck and have been working on this for hours and hours and can't figure out my next step....heres the program assignment. This vending machine dispenses 1. M&Ms ($.65), 2. Chips...
9
by: vpascuzzi | last post by:
Here's the deal: I've been working on this little program forever now, and can't seem to get the final little glitches out of it. I am to build a vending machine, using 2 header .h files (one...
7
by: JohnSmith70 | last post by:
Please help I need help with this homework. Its about vending machines, and it should be a piece of cake to you code experts out there. Its about vending machines. Heres the question: It...
2
by: nb999 | last post by:
Hello Friends, I was trying to simulate a vending machine using perl just as a fun project. Heres the code I wrote: #!/usr/bin/perl $wt = $ARGV;
1
by: Kunthea | last post by:
I am not that good at programming and I need a little push on how I can start my programming on the vending machine. The basic of the homework is that it displays four snacks and corresponding...
3
by: ismaeel | last post by:
i very need for intrfase of vending machine for netbense sending to email plese
1
by: abil | last post by:
i've already build a program that contain all the price, the change given back to the customer but i dun have no idea which function i should use to do program print report... #include <cstdlib>...
3
by: exospire | last post by:
Hello everyone, I made a program that simulates a vending machine for class. I finally got it to execute without any errors, yet something is not right. I have functions that are being called upon...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.