How to properly code this C++ program

November 5, 2010 at 16:59:45
Specs: Windows 7
I'm a new C++ programmer and I'm having trouble with this programming assignment.

The instructions are :
Write a program that calculates the occupancy rate for each floor of a hotel. The program should start by asking the user how many floors the hotel has. Next, a loop should then iterate for each floor. For each iteration, the loop should ask the user for the number of rooms on the floor and how many of them are occupied. After all the iterations, the program should display how many rooms the hotel has, how many of them are occupied, how many are unoccupied, and the percentage of the rooms that are occupied.

I don't know how to program the calculation. How do you add together the number of rooms if the value for variable keeps changing? If the solution is simple and I'm missing it, please offer some advice on how to code this program.. Help would be much appreciated so I can better understand C++.

Here is the code that I have so far:


int numFloors, loopCount, numRooms, numOccupied ;

cout << "How many floors are there? " ;
cin >> numFloors ;

for ( loopCount = 1; loopCount <= numFloors; loopCount++ ) {
if ( loopCount == 13 )
continue ;

do {
cout << "How many rooms on floor " << loopCount << "? " ;
cin >> numRooms ;

if (numRooms < 10 ) {
cout << "Enter 10 or more for the number of rooms." ;
cin >> numRooms ;
} // end if

cout << "How many of the rooms are occupied? " ;
cin >> numOccupied ;

} // end do

while ( numRooms > 10 ) ;

} // end for


See More: How to properly code this C++ program

Report •


#1
November 8, 2010 at 20:46:12
1-- thank u because i got board from books I just wanna write something, (I am beginner, too)
2-- I think if you use the class style it will be more easier specially with the biggest programs.
3-- Here you can put the (math or calculation) code at the end of while---do loop:
and better.
something like this :

main()
{
int numRooms, numOccupied, busyRooms, numFloors;

cout << "Enter the number of floors : ";
cin >> numFloors;

for (int loopCount=1; loopCount <= numFloors; loopCount++)
{
do {
cout << "How many rooms on floor " << loopCount << "? " ;
cin >> numRooms ;

if (numRooms < 10 ) {
cout << "Enter 10 or more for the number of rooms." ;
cin >> numRooms ;
} // end if

cout << "How many of the rooms are occupied? " ;
cin >> numOccupied ;

busyRooms = (numOccupied * 100) / numRooms;
cout << "the busy rooms' rate for floor " << loopCount << " is : " << busyRooms << "%" << endl;

} while ( numRooms > 10 ) ; // end do---while loop
}
}

so try it and Plz tell if I miss something because my english it's not very good.
and if you have other questions just tell me because write a code more challenge than reading a book.



Report •
Related Solutions


Ask Question