Please help! I'm new to programming and my Program is outputting user's input twice.
Right now It looks like this when its outputted:
Floor Room Available Occupied Occupancy Rate
1 15 10 5 33.33%
2 15 10 5 33.33%
QUESTION: I realized an array is needed but what would it look like if I want the user inputs reciprocated in my table? This is what my code looks like now.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//Variable Definitions
int Floors;
double Rooms, occupied;
char choice;
int count = 1;
//Retrieving Floors of Hotel from User
cout << "\nFirst, tell us how many floors does the hotel have: " << endl;
cin >> Floors;
//Not accepting an answer floors less than 1
if (Floors > 0) {
//Using For loop to ask the user to enter the total number of rooms for each floor.
for (; count <= Floors; count++) {
cout << "How many rooms does floor " <<count << " have: " << endl;
cin >> Rooms;
//User should enter Y or N on whether any rooms are occupied, if enter anything other than those
// letters, need to re-enter right choice.
cout << "Are any of the rooms occupied on this floor? (Enter Y for Yes or N for No): " << endl;
cin >> choice;
if (choice == 'Y') {
cout << "Enter amount of rooms occupied: " << endl;
cin >> occupied;
}
else if (choice != 'Y' && choice != 'N') {
cout << "Wrong Answer Choice, please answer with Y or N: " << endl;
cin >> choice;
cout << "Re-Enter amount of rooms occupied: " << endl;
cin >> occupied;
}
if (occupied > Rooms) {
cout << "Error: The amount occupied cant surpass total number of rooms on that floor. Please re-enter choice: ";
cin >> occupied;
}
}
//Formatting Table
cout << setw(10) << "Floor" << setw(10) << "Room" << setw(10) << "\tAvailable"
<< setw(10) << "Occupied" << setw(15)<< "\tOccupancy Rate " << setw(10)<< endl;
cout << " ------------------------------------------------------------------";
//!!!Can't get this part to output data, repeating data.
for (int x = 1; x <= Floors; x++) {
cout << "\n" << setw(10) << x << setw(10);
cout << Rooms << setw(10);
cout << Rooms - occupied << setw(10);
cout << occupied << setw(10);
cout << "\t" << (occupied / Rooms) * 100 << "%" << setw(10) << endl;
}
}
//This is printed if user enter invalid floors from beginning
else {
cout << "\nIncorrect: Please enter floor numbers more than 1: " << endl;
cin >> Floors;
}
return 0;
}