I'm fairly new to C++ and have an assignment that is knocking me out. The text file is fairly simple:
Plain Egg
1.45
Bacon and Egg
2.45
Muffin
0.99..... etc....
And the code is:
//Breakfast Billing System
//Marlen LaBianco
//May 20, 2007
//Program to calculate a local restaurant's breakfast billing system
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
const int Breakfast_Items = 8;
struct menuItemType
{
string menuItem;
double menuPrice;
};
menuItemType menuList[Breakfast_Items];
ifstream inMenu1;
ofstream outMenu;
void getData ();
void showMenu ();
int main()
{
string inputMenu;
string outputMenu;
inMenu1.open("itemNo.txt", ios::in);
if (!inMenu1)
{
cout << "Cannot open the input file." << endl;
return 1;
}
getData ();
showMenu ();
inMenu1.close();
outMenu.close();
return 0;
}
void getData ()
{
int index;
string menuItem;
string item;
double price;
for (index = 0; index < 8; index++)
{
getline(inMenu1, menuList[index].menuItem);
item = menuList[index].menuItem;
inMenu1 >> menuList[index].menuPrice;
price = menuList[index].menuPrice;
cout << item << setw(15) << setprecision(2)
<< setiosflags(ios::fixed) << right << "$"
<< price << endl;
}
}
void showMenu ()
{
int index;
int maxIndex = 0;
cout << "Restaurant Breakfast Menu" << endl;
for (index = 0; index < 8; index++)
{
cout << menuList[index].menuItem << setw(15) << setprecision(2)
<< setiosflags(ios::fixed) << right << "$"
<< menuList[index].menuPrice << endl;
}
}
And this is what the program is giving out:
Plain Egg $1.45
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
Restaurant Breakfast Menu
Plain Egg $1.45
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
$0.00
Please help!
Woody