473,325 Members | 2,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Reading from file

6
hey guys, I have this program to do, but I kind of started forst just te read things from the file and then I would go and make the calculation but it is showing some wierd funnky resualts, I dont know why is now outputing what is in the file,
this is the program

A file called Stock.txt contains information regarding the 9 different stock items carried by FUNNY STUFF RETAIL INC. The file is a repeating sequence of three records such that the first record represents an item code number, the second record represents the description of each item and the third record contains the current selling price. Then the sequence repeats. Your program is to simulate the check out register allowing the check out clerk to input item codes to obtain the current selling prices and descriptions. If an incorrect code is entered, the clerk should be notified by an appropriate message on the screen. The clerk will enter the number of items with that description and price and continue to the next item. When all items have been entered the clerk terminates the transaction by entering an item code of 0 (zero). The program will build a sales slip enumerating the item code, description, unit price, quantity purchased, and total extended price. The bill will be subtotaled and an 8% sales tax added for a final total. Amount tendered by the customer and change given will be finally added to the invoice. This invoice should be written out to an output file and the user should be prompted for the output file name. The final total and change should appear on the screen as well.
Your output file should line up all columns with the item code and description left justified and the numeric decimals lined up.

Upload your .cpp file named Lab3.cpp, your pseudocode file named Lab3.txt, and your Stock.txt data file.

The following is the information that is to be put into a file called Stock.txt that will be used as the stock information to be used at the checkout in your program.

Item Code Description Price
1235 Womens Stockings 12.39
2865 Mens Pajamas 17.99
4020 Cotton Dress 23.00
3640 Sweater 20.50
5109 Short Set 56.99
4930 TV Set 88.20
6600 Electric Tooth Brush 94.55
5020 Aluminum Pan 16.79
2336 Pencil Set 4.55





Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int main()
  5. {
  6.     ifstream inFile;
  7.     int item;
  8.     float price;
  9.     char description;
  10.     inFile.open("sock.txt");
  11.     cout<<"Reading 9 items form stock file.\n\n";
  12.  
  13.     inFile>>item;
  14.     inFile>>price;
  15.     inFile>>description; 
  16.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  17.  
  18.     inFile>>item;
  19.     inFile>>price;
  20.     inFile>>description;
  21.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  22.  
  23.  
  24.     inFile>>item;
  25.     inFile>>price;
  26.     inFile>>description;
  27.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  28.  
  29.  
  30.     inFile>>item;
  31.     inFile>>price;
  32.     inFile>>description;
  33.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  34.  
  35.  
  36.     inFile>>item;
  37.     inFile>>price;
  38.     inFile>>description;
  39.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  40.  
  41.     inFile>>item;
  42.     inFile>>price;
  43.     inFile>>description;
  44.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  45.  
  46.     inFile>>item;
  47.     inFile>>price;
  48.     inFile>>description;
  49.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  50.  
  51.     inFile>>item;
  52.     inFile>>price;
  53.     inFile>>description;
  54.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  55.  
  56.     inFile>>item;
  57.     inFile>>price;
  58.     inFile>>description;
  59.     cout<<"Item number : "<<item<< " " <<price<< " "<<description <<endl;
  60.  
  61.     inFile.close ();
  62.     system("pause");
  63.     return 0;
  64. }
  65.  
Feb 20 '07 #1
1 2100
DeMan
1,806 1GB
What are the Wierd Funky results?
Feb 21 '07 #2

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

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
19
by: Lionel B | last post by:
Greetings, I need to read (unformatted text) from stdin up to EOF into a char buffer; of course I cannot allocate my buffer until I know how much text is available, and I do not know how much...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
6
by: Rajorshi Biswas | last post by:
Hi folks, Suppose I have a large (1 GB) text file which I want to read in reverse. The number of characters I want to read at a time is insignificant. I'm confused as to how best to do it. Upon...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
5
blazedaces
by: blazedaces | last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.