I can\'t get this program to run... I use gcc programname.c but I keep getting t
ID: 3658072 • Letter: I
Question
I can't get this program to run... I use gcc programname.c but I keep getting the same error. Can someone help me with this. I prefer to use scanf,prinf and if statements if possible. Please include screen shot if possible #includeusing namespace std; int main() { int floors = 6, rooms = 20, suites = 120, occupied = 0, totalRooms = 120; int totalOccupied = 0, totalUnoccupied = 0, numFloors=16; int occupRate,floor; //store hotel occupancy rate for (floor = 10; floor <= numFloors; floor++)//initiate loop { if (floor==13) { floor=14; } cout<<"Enter the number of rooms occupied on " << floor << "floor. "; cout<<"occupied:"<<occupied; while(occupied>20 | occupied<0) { cout<<"Invalid Entry "; cout<<"Enter the number of rooms occupied on " << floor << "floor. "; cout<<"occupied:"<<occupied; } totalOccupied += occupied; //number of rooms in each floor will be added to totalRooms totalUnoccupied = totalRooms - totalOccupied; //store total ofunoccupied rooms in hotel } occupRate=(totalOccupied*100)/totalRooms//store occupancy rate cout<<" The hotel has " << totalRooms << " rooms. "; cout<<totalOccupied << " rooms are occupied. "; cout<<totalUnoccupied << " rooms are unoccupied. "; cout<<occupRate << "% of the rooms are occupied. "; //displayoccupancy rate in percentage format getch(); return 0; }Explanation / Answer
#include #include using namespace std; int main() { int numfloors; double occupied, roomperF, totalSuites, occpRate = 0.0, totalOccp; // Get the number of rooms per floor cout roomperF; // Validate the Input while (( roomperF) < 0 || (roomperF > 20)) { cout roomperF; } // Enter the number of the top floors on Hotel cout > numfloors; //Get the number of occupied rooms per floor for (int floor = 10; floorRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.