473,465 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with code using struct and arrays

3 New Member
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
2 1891
DeMan
1,806 Top Contributor
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
mac11
256 Contributor
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

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

Similar topics

1
by: AKF | last post by:
I am trying to use data structures to open a file (void display_Stock_Item(Stock_Item si);) from a text file. I also need to be able to write to the file and also to delete from the file using...
3
by: Sourin | last post by:
Hi all, I am trying to write code for my experiments. My work involves huge datasets, and as such my code needs to be memory efficient. I did some hand calculations regarding the amount of...
6
by: berthelot samuel | last post by:
Hi everyone, This really is a tricky one ! (at least for me:). Actually I haven't found any solution to this problem anywhere... So I'll try to be as clear as possible in my explanations. First,...
2
by: ANaiveProgrammer | last post by:
Hi all I have been trying to send a struct over socket. I tried to assign the values of struct to unsigned char array. I have attached both .c files at the bottom. 'Client.c' takes a struct,...
2
by: Pasacco | last post by:
dear I want to ask help on this problem. Array a is partitioned into a0 and a1 in main(). Then a1 is partitioned into a2 and a3 in th_partition() function. And I think this problem is something...
4
by: kelli | last post by:
i am new to c# so if this is a trivial problem, forgive me! i've searched the web and after 2 days still cannot solve it. i am converting a c++ application to c# - the problem code is listed...
10
by: csshine | last post by:
I composed below code but can not pass compiling. Could some one help this? ------------------------------ #include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; ...
5
by: aaragon | last post by:
Hello everybody, I appreciate your taking the time to take a look at this example. I need some help to start the design of an application. To that purpose I'm using policy-based design. The...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.