displaying only true items

i have been writing this script, for someone. but i cant figure out the smallest thing

i need help trying to display the selected menu items, only. with price and all that...

if anyone could help i would so happy



#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;


struct menuItemType
{
string menuItem;
double menuPrice;
bool selected;
};


int main()
{

menuItemType menu[10];
int i = 0;
int choice;






ifstream infile;
infile.open("menu.txt");
do
{
getline(infile, menu[i].menuItem);
infile >> menu[i].menuPrice;
infile.get(); // to get of the eol character after the priceinfile >> menu[i].menuPrice;
menu[i].selected = false;
i++;
} while (infile);// set the selected member to false

cout << "Menu Choices" << endl;

for (i = 0; i < 8; i++)
{
cout << fixed << setprecision(2);
cout << i + 1 << "." << menu[i].menuItem << setw(25) << right << menu[i].menuPrice << endl;
}
cout << endl << "Or 9 to Exit" << endl << endl;
do{
cout << "Enter the number of the item you would like: ";
cin >> choice;
menu[choice - 1].selected = true;

}while (choice != 9);



for (i = 0; i < 8; i++)
{
if(menu[choice - 1].selected = true)
cout << i + 1 << "." << menu[choice - 1].menuItem << setw(25) << right << menu[i].menuPrice << endl;
}

return 0;
}
- I suggest you use code tags(the "<>" button) when you post your code on here.

- Moreover, printing out menu items is simply outputting your variables to the screen with spaces where necessary,etc.
Topic archived. No new replies allowed.