Help with a "restuarant menu"

0 Lé Pig · December 1, 2015
   Hey everyone. I've been hacking away at this assignment for the past 2 weeks and I just can't frickin get it. I have a restaurant menu (two arrays in a struct) and I am supposed to be able to list all items and prices (this part works fine) and then I'm supposed to be able to choose any individual item to add to an order. So for example if someone wants eggs, I input 0, if someone wants french toast I input "3" and so on. Then  when the person is done ordering, I need to add the total and print the bill.

   In my code I have the input as a for loop, but I can't figure out how to do it. I keep adding up numbers that are not referencing the array. Please help! Sorry I didn't use code tags, they never seem to work, but this is what I have so far.

#include <iostream>
#include <string>

using namespace std;

float sum;
int itemsOrdered;

struct menuItem
    string breakfastItem[8];
    float itemPrice[8];

void setMenu()
    dish.breakfastItem[0]= "0. Plain Eggs -- $1.45\n";
    dish.itemPrice[0]= 1.45;
    dish.breakfastItem[1]= "1. Bacon and Eggs -- $2.45\n";
    dish.breakfastItem[2]="2. Muffin -- $0.99\n";
    dish.breakfastItem[3]="3. French Toast -- $1.99\n";
    dish.breakfastItem[4]="4. Fruit Basket -- $2.46\n";
    dish.itemPrice [4]=2.46;
    dish.breakfastItem[5]="5. Cereal -- $0.69\n";
    dish.breakfastItem[6]= "6. Coffee -- $0.50\n";
    dish.breakfastItem[7]="7. Tea -- $0.75\n";

float showMenu()

            for(int i=0; i<=7;i++)
        cout << dish.breakfastItem;

       for(int j=0;j<99;j++){

        cin >> dish.itemPrice[j];
    sum = sum + dish.itemPrice[j];
    cout << sum;


int main()


Post a Reply


- page 2
Oldest  Newest  Rating
0 Lé Pig · December 1, 2015
See, this is where I want to light my C++ book on fire. I've been working on my code for the past 2 weeks because someone in my class was helping me build it the way I showed you (until I got stuck). He knows what he's doing, he's a programmer, he'd make it work. Then suddenly everything I'm doing is wrong. What do I do about that?

and that's alright Dan. I appreciate the help. Now I'm gonna have to wipe my brain and go over everything new and everything I thought I knew and bleh...this is hard.
0 c student · December 1, 2015

What I don't understand is how to choose the value [0] for example and add it to another variable.

okay, i need you to clarify what you mean by this.  is the "other variable" the sum of the bill and the value [0] an item on the menu?
you wish to add the price of the chosen item on the menu to the bill amount, correct?
0 Joe Vunderslaush · December 2, 2015
using namespace std;

//Builds struct
struct menu{
    string items[8];
    float price[8];

//Sets Values to arrays
void setMenu(){
    dish.items[0]= "0. Plain Eggs -- $1.45\n";
    dish.price[0]= 1.45;
    dish.items[1]= "1. Bacon and Eggs -- $2.45\n";
    dish.items[2]="2. Muffin -- $0.99\n";
    dish.items[3]="3. French Toast -- $1.99\n";
    dish.items[4]="4. Fruit Basket -- $2.46\n";
    dish.items[5]="5. Cereal -- $0.69\n";
    dish.items[6]= "6. Coffee -- $0.50\n";
    dish.items[7]="7. Tea -- $0.75\n";
//Displays Items
void showMenu(){
    for(int i = 0;i < 8;i++){
This code should be exactly what your asking for unless i missed something.
  • 1
  • 2



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator