我必须编写一个程序,使用 for 循环来询问酒店有多少层,然后询问用户每层的房间数和占用的房间数。最后,我将把所有房间加起来,有多少房间被占用,多少房间未被占用,并根据这些数字给出百分比。到目前为止,我所拥有的只是循环,而我的求和功能现在给了我惊人的数字。
#include <iostream>
using namespace std;
int main ()
{
int floor, room, occupy, total_unoccupy, total_occupy, total_room;
cout << "How many floors are in the hotel?\n";
cin >> floor;
for ( ;floor >= 1; floor--)
{
cout << "How many rooms are on floor " << floor << "?" << endl;
cin >> room;
cout << "How many of these rooms are occupied?" <<endl;
cin >> occupy;
}
total_room += room;
cout << "The total number of rooms are " << total_room << "." << endl;
return 0;
}