Okay, mein Problem ist, jedes Mal, wenn ich den Code laufen lasse und irgendetwas in den Zeilen 5 - 9 wähle, wird der Counter nicht aktualisiert, aber der Business Class Counter hilft bitte!Warum erhöht der Klassenzähler die Coach-Klasse nicht?
#include<iostream>
#include<string>
#include <iomanip>
using namespace std;
#include "C:\Users\barta\OneDrive\Documents\Visual Studio 2015\Projects\Project 4\Project 4\array.h"
void displayPlane(char msg[], char[ROW][COL]);
void getData(int &, char &);
void salesReport(int classCtr[],double fare[], string classes[]);
int main()
{
int row = 0;
char seat;
while (row != -1)
{
displayPlane("\tChesapeaake Airlines", layout);
cout << endl;
getData(row, seat);
if (row == -1)
break;
cout << endl;
int COL = seat - 'A';
if (layout[row - 1][COL] == 'X')
{
cout << "Sorry this seat is taken" << endl;
}
else
{
layout[row - 1][COL] = 'X';
}
}
double percentOccupied;
std::cout << std::fixed;
std::cout << std::setprecision(2);
int total = 0;
for (int i = 0; i < 2; i++)
{
total += classCtr[i];
}
cout << setw(18) << "Total Seats = " << total << endl;
percentOccupied = ((double)total/36) * 100;
cout << setw(22) << "Percent Occupied = " << percentOccupied << endl;
salesReport(classCtr, fare, classes);
cout << endl;
cout << "Have a nice day! " << endl;
system("pause");
return 0;
}
void displayPlane(char msg[] , char[ROW][COL])
{
cout <<msg << endl;
for (int r = 0; r < ROW; r++)
{ cout << endl;
cout << setw(4) << r + 1;
for (int c = 0; c < COL; c++)
{
cout << setw(4) << layout[r][c];
}
}
}
void getData(int& row, char& seat)
{
cout << "Enter row <-1 to stop> ";
cin >> row;
if (row == -1)
return;
if (row == 1)
{
classCtr[0]++;
}
else if (row == 2 || 3 || 4)
{
classCtr[1]++;
}
else if (row == 5 || 6 || 7 || 8)
{
classCtr[2]++;
}
cout << "Enter your prefered seat ";
cin >> seat;
seat = toupper(seat);
}
void salesReport(int classCtr[], double fare[], string classes[])
{
cout << " \tTicket Price" << setw(20) <<"Total Sales\n\n"
<< setw(14) << classes[0] << "\t" << fare[0] << setw(6) <<classCtr[0] << "\n\n"
<< classes[1] << "\t" << fare[1] << setw(6) <<classCtr[1] <<"\n\n"
<< setw(14) << classes[2] << "\t" << fare[2] << setw(6) << classCtr[2];
}
die Header-Datei:
//arrays for airline problem
const int ROW = 9;
const int COL = 4;
const int CTR = 3;
//initial seats in the plane
char layout[ROW][COL] = { { 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' },
{ 'A', 'B', 'C', 'D' }};
int classCtr[CTR] = {0,0,0};
string classes[] = {"First Class", "Business Class", "Coach"};
double fare [] = {500, 300, 100};
Hier ist die löschte, wenn ich den Code Chesapeaake Airlines laufen
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 5
Enter your prefered seat a
Chesapeaake Airlines
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 X B C D
6 A B C D
7 A B C D
8 A B C D
9 A B C D
Enter row <-1 to stop> 7
Enter your prefered seat c
Chesapeaake Airlines
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 X B C D
6 A B C D
7 A B X D
8 A B C D
9 A B C D
Enter row <-1 to stop> 9
Enter your prefered seat d
Chesapeaake Airlines
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 X B C D
6 A B C D
7 A B X D
8 A B C D
9 A B C X
Enter row <-1 to stop> -1
Total Seats = 3
Percent Occupied = 8.33
Ticket Price Total Sales
First Class 500.00 0
Business Class 300.00 3 <------See this is where the rows are being updated
Coach 100.00 0 <---- but i need rows 5 - 9 to be updated here
Have a nice day!
Press any key to continue . . .
Vielen Dank! Mann! und das macht Sinn! Meine Logik war nicht die beste Lmao –