Im trying to write a program that will calculate ticket sales for 3 different ticket types and then add the sales together for a total dollar amount. The instruction are to use an text input file but no output file. Im currently trying to make sure that the input data goes into the .txt file.
Here's my issues:
1)Every time I debug, I cant seem to get the program to "wait" for the different input types.It asks for the three ticket amounts and the prices, one question directly after another. I have a cout calculation line using static_cast and the assigned variables, but since the program doesn't "wait", I get a wrong output.
2) I check the input.txt file to see if the numbers that I entered have been entered, but they haven't been in the file yet. Every time I Debug I check the file and haven't had anything show up. I haven't gone any farther because using the input file was the point of the assignment and I cant even get that to work right,lol.
#include<iostream>
#include<fstream>
usingnamespace std;
int main ()
{
//Declare Variables
ifstream infile;
int Bnum,Snum,GAnum;
float Bprice, Sprice, GAprice;
//open file
infile.open("TicketsTextFile.txt");
//collect input
cout<<"Please enter the number of Box, Sideline, and General Admission tickets" <<endl;
infile>>Bnum>>Snum>>GAnum;
cout<<"Please enter the price of Box, Sideline, and General Admission tickets"<<endl;
infile>> Bprice>>Sprice>>GAprice;
cout<<"Total number of tickets is:"<<static_cast<int>(Bnum+Snum+GAnum)<<endl;
infile.close();
cin.get();
cin.get();
return 0;
}
What I thought would happen is that I would at least be able to see the entered data in the input .txt. file, and see the number of total tickets sold. ( from the calculation on line 22). Im sure many people have done this problem but for some reason Im not conceptualizing things in the right way or something.
I was thinking about it wrong. So I should think of it as: input is now coming from the file, instead of the users keyboard? (user is who ever is "using" the program. I.E.-After hitting the de-bug button I am the user.)
The way I had previously viewed it was that the input from the keyboard went into the input file and then the data was manipulated.
Im going to do some re-working of things, thanks very much!
I've got the proper data in my input file now, but my manipulation of the data is wrong. I entered in a basic multiplication equation in the static_cast line just to see if I was getting the right number assigned to the variables I wanted. Didn't workout too well, got a really big number. I know getline can read entire lines, but Im trying to read one number from the file and assign it to a variable.
#include<iostream>
#include<fstream>
#include<iomanip>
usingnamespace std;
int main ()
{
//Declare Variables
ifstream infile;
int Bnum,Snum,GAnum;
float Bprice, Sprice, GAprice;
//open file
infile.open("TicketsTextFile.txt");
//read data
infile>>Bprice>>Bnum>>Sprice>>Snum>>GAprice>>GAnum;
//calculate
cout<<"Total number of Box cash is:"<<fixed<<showpoint<<setprecision(2)<<static_cast<float>(Bnum*Bprice)<<endl;
infile.close();
cin.get();
cin.get();
return 0;
}
I thought I remember my Prof. saying that white space inside the file was the delineation line for data entry. The "infile>>" line would read every number in order and assigned those variables to the numbers that matched in order (first number goes to first variable, second number goes to second variable, etc).
I have also just tried using the 2 variables in the equation to declare (Bnum and Bprice), deleting the other names to eliminate possible errors and Im still getting the same giant number.