Link to home
Start Free TrialLog in
Avatar of Tammaria
Tammaria

asked on

Another C++ program

Write a program that reads the data in a text file of ticket prices and number of tickets sold, calculating the number of tickets sold and total sales amount.

I have the numbers in notepad saved to use.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tammaria
Tammaria

ASKER

I had saved the problem to my Document folder and put it my compiler. I was having a problem with it running in my VS Express compiler. I got with one of my classmates and she showed me what the problem was. The compiler was saying that the library was "deprecated". I had to go to the source file and add to open it up to put in my program and ran it from there. I thought I was doing something wrong in my program but it was not. Sorry for the confusion. I can send you the copy of my program if I need to. Thank you.
I imagine that at this point in the class you don't need to be linking libraries. You should probably be using a Win32 Console application and 'Empty Project' so that all it uses is your c++ code and it doesn't try to wrap its own libraries around everything.
I have it fixed now. When I ran my program on my computer I was having multiple error messages. Then when I took it to school, which wasn't until yesterday, I ran it on their computer and it worked without errors. It was in my compiler. It is not homework but work we did in class that the instructor put onto the board and we put into our compilers. I could not figure out why it was running with errors but it is not now. Thank you for your assistance.
The linking libraries was part of the issue. I had to go into the Source File and add new to pull the compiler to get my program to run. I have my program attached. It did the output like it was supposed to but did show a negative on the second set of numbers. I do not think it was supposed to do this. Take a look at it and see what I may have wrong. The information was given to us by my professor so it should be correct but puts out a negative amount.
TotalTicketSales.cpp
Lab2Data.txt
You set it up to display decimals, but then you only used ints. That seems odd.

The negative numbers are clearly wrong. It shows negative for all of them?
My guess is that the text file did not open. Make sure you check that it opened properly before you use it (your notes or book will show you the way your professor wants you to do it). Also, are you sure it's a good idea to hard code four of the same blocks of code like that? What if the text file had 20 lines instead of 4? If your grader has any sense of dignity, he will count off a lot of points. You should be using your file I/O techniques to see when you reached the end of the file or at least use a for loop.