Hi,
I have managed to get my program to work, and it looks great. But the output is not exactly what I want. In the print function, the loop seems to be repeating some items. This shouldn't be the case. This is my first time here, but I will appreciate any help. Thanks in advanced.
[This is my code]
//Assignment IV- Restaurant Menu: Nathaniel Cooper; Nov. 8, 2015
//This program automate the breakfast billing system of Cooper's restaurant.
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
cout << "\nEnter the number of your selection until you have completed your order. \n";
cout << "Enter 9 when you are done. \n";
}
int getData(ItemType MenuList[], ItemType OrderedList[], int Max)
{
int choice;
int counter = 0;
do{
cout << "What would you like? If you done ordering (enter 9): \n";
cin >> choice;
if(choice < 1 || choice > 9)
{
cout << "\a\a Invalid Input \n";
cout << "Enter the number of your selection. \n";
cin >> choice;
}
if(choice !=9)
OrderedList[counter].item_name = MenuList[choice-1].item_name; //enters item name in order
OrderedList[counter].UnitPrice = MenuList[choice-1].UnitPrice; //enter price in order
counter++;
}while(choice !=9 && counter < Max); //repeats the whole thing until 9 is entered
I edited it. I also did the 'add the code tag.' I don't know if this makes sense, in the print function, the loop repeats the first item twice. This shouldn't be the case.
I want to print out the items, but I don't want any items to be repeated.
Those this make sense?
Please, use code tags (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your
post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <>
formatting button.
if(choice !=9)
OrderedList[counter].item_name = MenuList[choice-1].item_name; //enters item name in order
OrderedList[counter].UnitPrice = MenuList[choice-1].UnitPrice; //enter price in order
I guess should be
1 2 3 4 5
if(choice !=9)
{
OrderedList[counter].item_name = MenuList[choice-1].item_name; //enters item name in order
OrderedList[counter].UnitPrice = MenuList[choice-1].UnitPrice; //enter price in order
}
The problem is in the function getData().
counter gets incremented once to often and then of course in printCheck it will print one item to much.
There is also a small problem with the alignment of the output.