472,780 Members | 1,200 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

what do i do to make my program compare price and money deposited?

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(double *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_cost)
return 0;
else if(money>=item_cost)
return 1;
printf("Welcome to Vend-O-Matic\n");

return 0;
Oct 26 '09 #1
1 1642
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(double 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(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(payment<item_cost)
return 0;
else if(payment>=item_cost)
{
printf("Welcome to Vend-O-Matic\n");
return 1;
}
return 0;
}
Oct 26 '09 #2

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

Similar topics

17
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...
9
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
0
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...
47
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...
1
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
1
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...
1
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...
9
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...
3
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.