Hello! I am in my first year in the CS major at a university and I am a little confused about what's going wrong here in this code. Basically my issue is for example: The first if statement in the code states that if the input value is over 1000, it asks the user for a new value. BUT, if you enter another value over 1000 the second time, it just moves on to the next section of the code. This repeats itself in different situations through this code. The equations and everything in the problem work fine, this is my only problem. Can anyone help / explain?
Code:
#include <stdio.h>
int main()
{
int room_length, room_width;
int table_length, table_width;
int space, people_table;
printf("What is the length of the room in feet?\n");
scanf("%d", &room_length);
if(room_length > 1000)
{
printf("Sorry, the room is too long, please give another length.\n");
scanf("%d", &room_length);
}
printf("What is the width of the room in feet?\n");
scanf("%d", &room_width);
if (room_width > 1000)
{
printf("Sorry, the room is too wide, please give another width.\n");
scanf("%d", &room_width);
}
printf("What is the length of each of the tables in feet?\n");
scanf("%d", &table_length);
if (table_length > 1000)
{
printf("Sorry, the tables are too long, please give another length.\n");
scanf("%d", &table_length);
}
printf("What is the width of each of the tables in feet?\n");
scanf("%d", &table_width);
if (table_width > 1000)
{
printf("Sorry, the tables are too wide, please give another width.\n");
scanf("%d", &table_width);
}
printf("How much space is required between each table in feet?\n");
scanf("%d", &space);
if (space > 10)
{
printf("Sorry, the space between each table is too large, please give another length.\n");
scanf("%d", &space);
}
int tables_across = (room_length-space)/(table_length+space);
int tables_wide = (room_width-space)/(table_width+space);
printf("How many people can each table seat?\n");
scanf("%d", &people_table);
if (people_table > 21)
{
printf("Sorry, that is too many people per table, please give another amount of people.\n");
scanf("%d", &people_table);
}
if (people_table < 3)
{
printf("Sorry, that is too many people per table, please give another amount of people.\n");
scanf("%d", &people_table);
}
printf("This arrangement seats %d people.\n", tables_across*tables_wide*people_table);
return 0;
}
Thanks!