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];

string itemNames [6];
itemNames[1]="Diet Coke";
itemNames[2]="Swiss Chocoalate";
itemNames[4]="Iced Coffee";

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:
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:

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:

cout<<"Press Enter to Continue...";

If you want more lengthy help, just reach me out at:

Last edited on
Registered users can post here. Sign in or register to post.