I Need Help Please :(

its a vending Machine problem
i need a program that displays

1. coke $1.20
2. Diet coke $1.00
3. Swiss Chocolate $1.40
4. Pulpy $1.50
5. iced coffee $1.55
6. Candy $0.95
7. End of transaction

each item name has to be in a array
and item price in another array.

one item can be chosen at a time, the vending machine should continuously display the menu, unless the transaction ends or if the customer has ran out of money
At the end of the transaction it should display the total cost

I need to use the following functions:

void displayHeader()- this function displays header(what this program does)

double readDeposite()- this function allow the user amount to be inserted

void showMenu(string[],double[])- this function receives a string array that contains item names and a double that contains item prices. this function will display a menu for users to choose.

int readSelection()- this function will read and return choice of item the user want to purchase. the choice read the user has to be returend back to the main function

double calculateTotalCost(doubel,double)-this receives two parameter: a double variable containing the current cost and another double variable containing the cost of another item.the function will calculate and return the total cost to the main function

double computeChange(double, double)- this function receives two parameters, a double containing the total cost and another double variable containing the intial deposite made into the vending machine. the function will compute the change the vending machine should give.

void displayChange (double)- this function will receive one parameter, a double variable containing the change to be given out by the vending machine,. the function will compute and display the number of notes and coins to be returned back to the user


#include <iostream>
using namespace std;
int main ()
{
void displayHeader ();
void showMenu (string[],double[]);

double itemPrices [6];
itemPrices[0]=1.20;
itemPrices[1]=1.66;
itemPrices[2]=1.40;
itemPrices[3]=1.50;
itemPrices[4]=1.55;
itemPrices[5]=0.95;

string itemNames [6];
itemNames[0]="Coke";
itemNames[1]="Diet Coke";
itemNames[2]="Swiss Chocoalate";
itemNames[3]="Pulpy";
itemNames[4]="Iced Coffee";
itemNames[5]="Candy";






system ("PAUSE");
return 0;
}

i'm stuck please help :(
Okay, for starters, what have you done? :) It'd be a good point for others to help if they could see what you've done so far.

This whole program hinges on basic functions and their parameter/return values.

For instance, the displayHeader() function would simply contain some cout statements to output the description of a program.

I noticed that you have two function prototypes inside your main function:
1
2
void displayHeader();
void showMenu(string[], double[]);


These prototypes (as they're called) cannot be inside another function. You'll have to move them outside of your main function, and before it:

1
2
3
4
5
6
using namespace std;

void displayHeader();
void showMenu(string[], double[]);

int main()


In addition, be sure to #include <string>. A lot of compilers automatically include this for you, and some header files indirectly include this header as well. BUT it's just good practice and in some cases, necessary. For example, Visual Studio will give you an error when you try to use cin>> on a string, unless you #include <string>.

Another thing you can change (I know this is probably for school, and ALOT of schools tend to use system("PAUSE") in their short examples ), but you can replace this with something along the lines of:

1
2
cout<<"Press Enter to Continue...";
cin.ignore();


If you want more lengthy help, just reach me out at:
sparkprogrammer@gmail.com

Cheers!
Last edited on
Topic archived. No new replies allowed.