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

Need Help with Box Office Program

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"

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>
  5. using namespace std;
  7. int main()
  8.     {
  10.         ifstream inFile;
  11.         const int SIZE = 25;
  12.         char movie[SIZE];    
  14.         int adult = 6;
  15.         int children = 3;
  16.         int gross_profit, net_profit, distributor, aticket, cticket;
  18.                 inFile.open("BoxOfficeReport.txt");
  20.         inFile >> movie;
  21.         cout   << "Name Of The Movie: " << movie << endl;
  23.         inFile >> aticket;
  24.         cout   << "Adult Tickets Sold: " << aticket << endl;
  26.         inFile >> cticket;
  27.         cout   << "Children's Tickets Sold: " << cticket << endl;
  29.         gross_profit = (aticket*adult)+(cticket*children);
  30.         net_profit = gross_profit * .20;
  31.         distributor = gross_profit * .80;
  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;
  37.         inFile.close();
  38.         return 0;
  39.     }
Feb 1 '08 #1
1 3781
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

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...
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...
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...
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...
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. ...
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
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...
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:...
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...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.