i have to develop this snack machine program that makes you chose a snack put money in and give change here is my code so far, what do i use so the program compare the price and money deposited, I also dont know how to initialize the snack prices and the deposited money.I know i declared and initialized them wrong Thank you so much in advance
char *selection;
double *payment;
int main()
{
char item_cost;
char selection=&item _cost;
double P=1.25,
S=1.35,
T=0.95,
C=1.50,
B=1.75,
N=1.40;
int money;
double payment=&money;
double 1=5.00,
2=1.00,
3=0.25,
4=0.10,
5=0.05;
//double *payment=&money ;
void Menu(char *selection); // Displays the list of snack items and prompts for the user’s choice
{
printf("Please enter a selection :\n");
printf("P – Potato Chips $1.25\n");
printf("S - Snickers Bar $1.35\n");
printf("T – Pop Tart $0.95\n");
printf("C – Cookies $1.50\n");
printf("B – Brownie $1.75\n");
printf("N – Nuts $1.40\n");
printf("Please enter your snack selection:\n");
scanf(" %c", &item_cost);
}
// void CoinMenu(double *payment); //displays menu of coins and gets user input of the coins deposited
{
printf("Please deposit your money by selection:\n");
printf("1 - $5.00\n");
printf("2 - $1.00\n");
printf("3 - $0.25\n");
printf("4 - $0.10\n");
printf("5 - $0.05\n");
printf("Deposit amount:\n");
scanf("%lf", &money);
}
int CheckMoney(doub le *payment, double item_cost); //compares the amount the user has deposited to the price of item selected.
//It returns 1 if the amount is at least enough to cover
//the cost, 0 if there is not enough.
if(money<item_c ost)
return 0;
else if(money>=item_ cost)
return 1;
printf("Welcome to Vend-O-Matic\n");
return 0;
1 1682
I hope the below code will help you...there may be compilation errors..I haven't compiled... #include<stdio. h>
char selection;//selection can be
// P,S,T,C,B or N
double payment;// amount corresponding to
//the selection
void Menu();
int CheckMoney(doub le item_cost);
void CoinMenu();
int main()
{
double item_cost;
double P=1.25,
S=1.35,
T=0.95,
C=1.50,
B=1.75,
N=1.40;
Menu();
if(selection==' P')
{
item_cost= 1.25;
}
else if(selection==' S')
{
item_cost = 1.35;
}
else if(selection == 'T')
{
item_cost = 0.95;
}
else if(selection==' C')
{
item_cost = 1.50;
}
else if(selection==' B')
{
item_cost = 1.75;
}
else if(selection==' N')
{
item_cost = 1.40;
}
CoinMenu();
int returnValue = CheckMoney(item _cost);
if (returnValue == 1)
printf("Pls collect your snacks from the tray;-)");
else
printf("you have not enough money to by snacks(-;");
return 0;
}
void Menu() // Displays the list of snack items and prompts for the user’s choice
{
printf("Please enter a selection :\n");
printf("P – Potato Chips $1.25\n");
printf("S - Snickers Bar $1.35\n");
printf("T – Pop Tart $0.95\n");
printf("C – Cookies $1.50\n");
printf("B – Brownie $1.75\n");
printf("N – Nuts $1.40\n");
printf("Please enter your snack selection:\n");
scanf(" %c", &slection);
if(selection==' P'||selection== 'S'||selection= ='T'||selection =='C'
||selection=='B '||selection==' N')
{
return ;
}
else
{
printf("You have entered wrong choice\n");
menu();
}
return 0;
}
void CoinMenu() //displays menu of coins and gets user input of the coins deposited
{
printf("Please deposit your money by selection:\n");
printf("1 - $5.00\n");
printf("2 - $1.00\n");
printf("3 - $0.25\n");
printf("4 - $0.10\n");
printf("5 - $0.05\n");
printf("Deposit amount:\n");
int choice;
scanf("%d", &choice);
if(choice == 1)
payment = 5.00;
else if(choice == 2)
payment = 1.00;
else if(choice == 3)
payment = 0.25;
else if(choice == 4)
payment = 0.10;
else if(choice == 5)
payment = 0.05;
}
int CheckMoney(doub le item_cost) //compares the amount the user has deposited to the price of item selected.
//It returns 1 if the amount is at least enough to cover
//the cost, 0 if there is not enough.
{
if(payment<item _cost)
return 0;
else if(payment>=ite m_cost)
{
printf("Welcome to Vend-O-Matic\n");
return 1;
}
return 0;
} Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: John Cho |
last post by:
// CHO, JOHN
#include<iostream>
class fracpri{
int whole;
int numer;
int denom;
|
by: Nathanael |
last post by:
Hi Guys,
You probably have heard of affiliate marketing before but what exactly is
affiliate marketing? In this introduction you'll find an explanation of the
basics of affiliate marketing.
The principle of affiliate marketing
The principles of affiliate marketing are pretty easy. A merchant who wants
to sell more may decide to offer an affiliate program. Using this affiliate
program he will attract webmasters of other sites, so...
|
by: ship |
last post by:
Hi
We need some advice: We are thinking of upgrading our Access database
from Access 2000 to Access 2004.
How stable is MS Office 2003? (particularly Access 2003).
We are just a small company and this is a big decision for us(!) It's
not just the money it's committing to an new version of Access!
|
by: Filips Benoit |
last post by:
Dear All,
Table: ArticleYearPrice
ART_ID
YEAR
PRICE
ART_ID YEAR PRICE
111 2006 1,00
111 2007 1,01
| |
by: sallyk57 |
last post by:
Help with following Programs:
Write two programs one where the performance rating here shoud be entered as a int where Excellent =1, Good= 2, Poor=3. an employee who is rated excellent will receive a 6% raise, one rated good will receive a 4% raise, and one rated poor will receive a 1.5% raise. Add the if... else... statements to program Salary to make it run as described above.
//...
|
by: gdarian216 |
last post by:
I am writing a multifile program and it worked when it was all in one file. I have gotten all of the errors out of the program except when I go to output the change the quarters are right but the dimes and pennies print out a long string of numbers. I can't figure out were these numbers are coming from. If anyone can help I will be appreciated.
This is my main.cpp code for the body of my program.
#include<iostream>
#include"vendlib.h"...
|
by: bb |
last post by:
Hi,
Are there any open source data types ( c++ classes ) for Money and/or
Price that I can inherit and customize for my use instead of writing
from the scratch?
Any help would be much appreciated.
Thanks.
|
by: 100grand |
last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one
product at a time, including the item number, the name of the product, the number of
units in stock, the price of each unit, and the value of the inventory of that product. In
addition, the GUI should display the value of the entire inventory, the additional attribute,
and the restocking fee.
Here is my Inventory program from 1 to 3:
package...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |