below is my code. I am getting junk numbers. The assignment instructions are as
ID: 3664070 • Letter: B
Question
below is my code. I am getting junk numbers. The assignment instructions are as follows. This is c++ in codeblocks.
INput: The user will be prompted to enter the number of box seat tickets sold and the number of general admission tickets sold from the keyboard.
Processing: The team charges $10.75 for a box seat ticket and $5.50 for a general admission ticket. The team pays the parking manager 12% of the gross ticket sales. On average, the snack bar (not owned by the team) makes $6.25 profit from each person attending the game. The program is to calculate the gross ticket sales, the amount paid to the parking manager, the snack bar profit, and the team profit (the total ticket sales minus the amount paid to the parking manager).
Output: The program will print the number of box ticket seats sold, the number of general admission tickets sold, the gross receipts from ticket sales, the amount paid to the parking manager, the snack bar profit, and the team profit.
//This program calculates the gross ticket sales, the amount paid
//to the parking manager, the snack bar profit and the team profit
#include <iostream>
using namespace std;
int main ()
{
const double BOX_SEAT = 10.75;
const double GEN_ADMISSION = 5.50;
const double PARKING_MAN_PAY = .12;
const double SNACKBAR_PROF = 6.25;
int numBox; //this is the number of box seats sold
int numGen; //this is the number of general admission tickets sold
double grossBox = BOX_SEAT * numBox;
double grossGen = GEN_ADMISSION * numGen; //this calculates the gross ticket tales
double parkPay = (numBox + numGen) * PARKING_MAN_PAY;//this calculates the amount paid to the parking manager
double snackProfit = (numBox + numGen) * SNACKBAR_PROF; //this calculates the snack bar profit
double gross = grossBox + grossGen;
double teamProfit = gross - parkPay;//this calculates the teams profit
cout<<" BALL GAME SALES AND PROFITS "<<endl<<endl;
cout<<"Enter the number of box seat tickets purchased then press enter: ";
cin >>numBox;
cout<< "Enter the number of general admission tickets purchased then press enter: ";
cin >>numGen;
cout<< "The gross receipts from ticket sales is: " <<gross<<endl;
cout<< "The amount paid to parking manager is: " <<parkPay<<endl;
cout<< "The snack bar profit is: "<<snackProfit<<endl;
cout<< "The team profit is: "<<teamProfit<<endl;
return 0;
what am I doing wrong???
Explanation / Answer
You are taking the input of numbox and numGen later in the program and calculating the costs before even taking the input. The correct way is to input both of them before and then calculate the grossbox and grossgen.
#include <iostream>
using namespace std;
int main ()
{
const double BOX_SEAT = 10.75;
const double GEN_ADMISSION = 5.50;
const double PARKING_MAN_PAY = .12;
const double SNACKBAR_PROF = 6.25;
int numBox; //this is the number of box seats sold
int numGen; //this is the number of general admission tickets sold
cout<<"Enter the number of box seat tickets purchased then press enter: ";
cin >>numBox;
cout<< "Enter the number of general admission tickets purchased then press enter: ";
cin >>numGen;
double grossBox = BOX_SEAT * numBox;
double grossGen = GEN_ADMISSION * numGen; //this calculates the gross ticket tales
double parkPay = (numBox + numGen) * PARKING_MAN_PAY;//this calculates the amount paid to the parking manager
double snackProfit = (numBox + numGen) * SNACKBAR_PROF; //this calculates the snack bar profit
double gross = grossBox + grossGen;
double teamProfit = gross - parkPay;//this calculates the teams profit
cout<<" BALL GAME SALES AND PROFITS "<<endl<<endl;
cout<<" the number of box tickets sold"<<numBox;
cout<<"the number of general tickets sold"<<numGen;
cout<< "The gross receipts from ticket sales is: " <<gross<<endl;
cout<< "The amount paid to parking manager is: " <<parkPay<<endl;
cout<< "The snack bar profit is: "<<snackProfit<<endl;
cout<< "The team profit is: "<<teamProfit<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.