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

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.itemPrice[1]=2.45;
    dish.breakfastItem[2]="2. Muffin -- $0.99\n";
    dish.itemPrice[2]=0.99;
    dish.breakfastItem[3]="3. French Toast -- $1.99\n";
    dish.itemPrice[3]=1.99;
    dish.breakfastItem[4]="4. Fruit Basket -- $2.46\n";
    dish.itemPrice [4]=2.46;
    dish.breakfastItem[5]="5. Cereal -- $0.69\n";
    dish.itemPrice[5]=0.69;
    dish.breakfastItem[6]= "6. Coffee -- $0.50\n";
    dish.itemPrice[6]=.50;
    dish.breakfastItem[7]="7. Tea -- $0.75\n";
    dish.itemPrice[7]=0.75;
}

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()
{
    setMenu();
    showMenu();


}



Post a Reply

Replies

- page 2
Oldest  Newest  Rating
+1 Dan P · December 1, 2015
Find someone who isn't talking bullsh*t?
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
#include 
#include
using namespace std;

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

//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.price[1]=2.45;
    dish.items[2]="2. Muffin -- $0.99\n";
    dish.price[2]=0.99;
    dish.items[3]="3. French Toast -- $1.99\n";
    dish.price[3]=1.99;
    dish.items[4]="4. Fruit Basket -- $2.46\n";
    dish.price[4]=2.46;
    dish.items[5]="5. Cereal -- $0.69\n";
    dish.price[5]=0.69;
    dish.items[6]= "6. Coffee -- $0.50\n";
    dish.price[6]=.50;
    dish.items[7]="7. Tea -- $0.75\n";
    dish.price[7]=0.75; 
}
//Displays Items
void showMenu(){
    for(int i = 0;i < 8;i++){
        cout
This code should be exactly what your asking for unless i missed something.
  • 1
  • 2

C++

107,325 followers
About

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

Links
Moderators
Bucky Roberts Administrator