I keep getting output in scientic notation can someone please help me fix my cod
ID: 672699 • Letter: I
Question
I keep getting output in scientic notation can someone please help me fix my code ASAP. I am not sure what i am doing wrong.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//displayMenu will display the menu for the
//user and returns the choice the user entered
int displayMenu()
{
int choice;
//display the menu
cout<<" Menu ";
cout<<"1. Display Seating Chart ";
cout<<"2. Reserve a seat ";
cout<<"3. Display total seats sold ";
cout<<"4. Display empty seats ";
cout<<"5. Total sales amount ";
cout<<"6. Exit ";
//prompt the user to enter his choice of operation
cout<<"Enter the choice: ";
cin>>choice;
//return the value
return choice;
}
//displayChart will display the seating chart
//of the airlines
void displayChart(char seat[15][6])
{
//declare an iterative variable
int i;
cout<<" Seating Chart of the Airline ";
cout<<" 1 2 3 4 ";
//for loop to display the first class seats
for(i=0;i<5;i++)
{
cout<<"Row "<<i+1<<" ";
cout<<seat[i][0]<<" "<<seat[i][1]<<" ";
cout<<seat[i][2]<<" "<<seat[i][3]<<" ";
}
//for loop to display the coach seats
cout<<" 1 2 3 4 5 6 ";
for(i=5;i<15;i++)
{
cout<<"Row "<<i+1<<" ";
cout<<seat[i][0]<<" "<<seat[i][1]<<" "<<seat[i][2]<<" ";
cout<<seat[i][3]<<" "<<seat[i][4]<<" "<<seat[i][5]<<" ";
}
}
//seatResevation will reserve the seats if available
void seatResevation(char seats[15][6])
{
//declare the two index values
int row=0, seat=0;
//execute the loop till the row and the seat values are
//zero
while (seat == 0 && row == 0)
{
//display the simple menu so that user can
//know how to enter the data
cout << " Choose the seat to reserve ";
cout << "(1 - 5) First Class, (6 - 15) Coach ";
cout << "Row : ";
cin >> row;
//depending on the user entered row
//display the user the seat numbers
if (row <= 5)
{
cout << "Seat (1 - 4): ";
}
else
{
cout << "Seat (1-6): ";
}
//prompt the user to enter the seat numbers
cin >> seat;
if(row <1 || row > 15 || seat < 1 || seat > 6 || seats[row-1][seat-1]=='@' )
{
cout<<"Invalid seat ";
seat=0;row=0;
}
else if(seats[row-1][seat-1] == '*')
{
cout<<"Seat already occupied. Please choose another seat. ";
seat=0;row=0;
}
else
{
seats[row-1][seat-1]='*';
}
}
}
//seatsSold function will display the total seats
//sold and each individual class seats sold.
void seatsSold(char seats[15][6])
{
//declare the required variables
int i,j,firstClass = 0,coachClass = 0;
//loop to check all the 15 rows
for(i=0;i<15;i++)
{
//loop to check the booking seats
//that are marked as '*'
for(j=0;j<6;j++)
{
if(seats[i][j]=='*')
{
if(i<5)
{
firstClass++;
}
else
{
coachClass++;
}
}
}
}
//display the values
cout<<" Seats Sold: "<<firstClass+coachClass<<" ";
cout<<"First Class Seats Sold: "<<firstClass<<" ";
cout<<"Coach Seats Sold: "<<coachClass<<" ";
}
//emptySeats function will display the available seats
//in the Airline
void emptySeats(char seats[15][6])
{
//declare the required variables
int firstClass = 0, coachClass = 0, rowpointer;
cout<<"Seats Empty ";
//loop to check the number of seats available
for(int i=0;i<15;i++)
{
rowpointer=0;
//condition to check the seats availability in first class
if(i<5)
{
for(int j=0;j<4;j++)
{
if(seats[i][j]=='#')
{
rowpointer++;
firstClass++;
}
}
}
//condition to check the seats availability in coach class
else
{
for(int j=0;j<6;j++)
{
if(seats[i][j]=='#')
{
rowpointer++;
coachClass++;
}
}
}
//display the row
cout<<"Row "<<i<<" : "<<rowpointer<<" ";
}
//display the total values
cout <<" Seats Empty: "<<firstClass+coachClass<<" ";
cout <<"First Class Seats Empty: "<<firstClass<<" ";
cout <<"Coach Seats Empty: "<<coachClass<<" ";
}
//totalSales function will display the total amount obtained
//from the sold seats
void totalSales(char seats[15][6], double seatRates[15])
{
double sales=0;
int row;
//loop to check the sold seats and then
//add the amount
for(int i=0;i<15;i++)
{
row=0;
for(int j=0;j<6;j++)
{
if(seats[i][j] == '*')
{
row++;
}
}
sales += row * seatRates[i];
}
//display the total amount of the sold seats
cout<<" Total Sales: $"<<sales<<" ";
}
//main function will initalise the variables and calls the
//required functions by passing the respective variables depending
//on the user choice
int main()
{
int priceFirstClass = 300; // Price of first class seats
int priceCoachHigh = 200; // Price of first 5 rows of coach
int priceCoachLow = 100; // Price of last 5 rows of coach
int counter = 0;
char seats[15][6];
double seatsCost[15];
int choice;
double seatPrices[3];
// Create SeatPrices.txt and write seat prices to it
ofstream outputFile("SeatPrices.txt");
outputFile << priceFirstClass << endl << priceCoachHigh << endl << priceCoachLow << endl;
// Close file
outputFile.close();
// Open File
ifstream inputFile;
inputFile.open("SeatPrices.txt");
// Read prices from file, store in seatPrices array
if (inputFile.fail())
{
cout << "Error opening File ";
}
else
{
while (!inputFile.eof())
for (counter = 0; counter < 3; counter++)
inputFile >> seatPrices[counter];
}
//loop to assign the array for seats
for (int i=0;i<15;i++)
{
for(int j=0;j<=6;j++)
{
if(i<5 && (j==5 ))
{
seats[i][j]='@';
}
else if (i > 5 && j==6)
{
seats[i][j]='@';
}
seats[i][j]='#';
}
}
//loop till the user selects to quit the operations
while(1)
{
choice = displayMenu();
switch (choice)
{
case 1:
displayChart(seats);
break;
case 2:
seatResevation(seats);
break;
case 3:
seatsSold(seats);
break;
case 4:
emptySeats(seats);
break;
case 5:
totalSales(seats, seatsCost);
break;
case 6:
system("Pause");
return 0;
break;
}
}
system("pause");
}