By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Help with code using struct and arrays

P: 3
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
Jun 4 '07 #1
Share this Question
Share on Google+
2 Replies


DeMan
100+
P: 1,806
Hi Woody714,

Welcome to thescripts. As this question is c/c++ related, I will mopve it to the appropriate forum. In future you can find this forum by selecting the various options available on the blue bar near the top of the screen. I hope the experts in the c/c++ forum can help you with this problem!!
Jun 4 '07 #2

100+
P: 256
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!
I didn't look at your code yet because I don't know what your trying to accomplish. What do you expect the output to be?
Jun 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.