我无法确定如何制作预订学习室的计划 1.在获取菜单的用户输入方面,我是否朝着正确的方向前进? 2.用户选择一个选项后,如何为其房间选择分配一个新值以显示为打开或不可用? (指针?)
#include <stdio.h>
int main(void)
{
int rm1 = 0;
int rm2 = 0;
int rm3 = 0;
int rm4 = 0;
int rm5 = 0;
int rm6 = 0;
int rm7 = 0;
int rm8 = 0;
int rm9 = 0;
int rm10 = 0;
int input;
while (input != 4)
{
printf("Welcome to the Study-Room-Reservation System.\n"); /* Asks for user entry */
printf("Please Select an Option.\n------------------------------------\n");
printf("1. Reserve study room.\n");
printf("2. Leave study room.\n");
printf("3. Check Availability.\n");
printf("4. Exit.\n");
scanf("%d", &input);
if (input == 1)
{
printf("Please enter room number you would like to reserve. \n");/* 1. Reserve a room */
scanf("%d" , &)
}
else if (input == 2)
{
printf("Please enter room number you would like to exit. \n"); /* 2. Exit a room */
}
else if (input == 3)
{
printf("The following rooms are available. \n"); /* 3. Show available rooms */
}
else
{
printf("Invalid Command.\n"); /* Invalid Command */
}
}
return 0;
}
答案 0 :(得分:0)
而不是
int rm1 = 0;
int rm2 = 0;
int rm3 = 0;
.
.
使用数组
int room[10]; //for 10 rooms
然后以类似的方式使用它,
if( room[i] == 0 )
//room vacant
else if( room[i] == 1 )
//room occupied