473,322 Members | 1,510 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,322 software developers and data experts.

Need Help with Box Office Program

1
am new to c++ and having problems running this program properly. Am suppose to create a data file using Notepad that stores the inputs for the program. Read the data from your input file. Also, instead of writing the output to the screen, write it to a file named BoxOfficeReport.txt.

I created a file with notepad and named it BoxOfficeReport.txt. in it I typed
"A Movie title"
382
127

It compiles but when i run it i get something like this
Name of the movie: y(arrow type sybol)B
adult tickets sold: 4270931
children's tickets sold: 0

can anyone help.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8.     {
  9.  
  10.         ifstream inFile;
  11.         const int SIZE = 25;
  12.         char movie[SIZE];    
  13.  
  14.         int adult = 6;
  15.         int children = 3;
  16.         int gross_profit, net_profit, distributor, aticket, cticket;
  17.  
  18.                 inFile.open("BoxOfficeReport.txt");
  19.  
  20.         inFile >> movie;
  21.         cout   << "Name Of The Movie: " << movie << endl;
  22.  
  23.         inFile >> aticket;
  24.         cout   << "Adult Tickets Sold: " << aticket << endl;
  25.  
  26.         inFile >> cticket;
  27.         cout   << "Children's Tickets Sold: " << cticket << endl;
  28.  
  29.         gross_profit = (aticket*adult)+(cticket*children);
  30.         net_profit = gross_profit * .20;
  31.         distributor = gross_profit * .80;
  32.  
  33.         cout   << "Gross Box Office Profit: " << gross_profit << endl;
  34.         cout   << "Net Box Office Profit: " << net_profit << endl;
  35.         cout   << "Amount Paid to Distributor: " << distributor << endl;
  36.  
  37.         inFile.close();
  38.         return 0;
  39.     }
Feb 1 '08 #1
1 3775
weaknessforcats
9,208 Expert Mod 8TB
You can't do this:
inFile >> movie;
movie is a char array. The >> operator will stop on the first whitespace character so all you get is A.

You wil; need to use the getline() method to fetch the entire string.

Then it shoud work OK.

You could test this with a movie title that has only one word and see of your code suddenly starts working.
Feb 1 '08 #2

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

Similar topics

2
by: RWC | last post by:
Hello, I have a problem. I recently uninstalled office 97 and re-installed it. When I went to open Access up, it would only open in RUntime mode. I uninstalled all runtime software from my...
4
by: Dalan | last post by:
After reading and experiencing the phenomenon of installing MS Office 2000 on a system that already has MS Office 97, or for that matter just Access 97 Runtime, I saw the ugliness that ensues. If...
6
by: Benjamin Walling | last post by:
We have 109 remote offices all running Sybase ASA Server. We collect data from these offices and consolidate it into our main server. I have written a program that will read from each office and...
2
by: somersbar | last post by:
im trying to get a table from a microsoft access database on a simple web form using visual basic.net. ive set up the database as a file dsn. this is my connection string: DBQ=C:\Program...
5
by: Michael Russell | last post by:
Hi all, Using C#, I've created a simple wrapper class for using Excel. I have Office Pro 2003 installed on my devel machine. The wrapper class works great, reading and writing to/from Excel. ...
1
by: larpup | last post by:
I have a A2000 mdb and it is missing Microsoft Outlook 9.0 library.... I see that it is not listed. How can I get this into my references? Lar
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
0
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3:...
0
by: Bill Fallon | last post by:
I am developing a VB.Net application with VS 2005 that opens an Excel workbook and populates the worksheet with data. I started developing the application with Office 2007 installed on my Vista...
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...
1
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
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.