c-我有三个输入,但它只允许我输入两个第一个,然后在第三个中断



这个程序确定房间的面积,它是房间长度和宽度的乘积。房间是"太小"、"刚刚好"还是"太大"。如果房间"太小"或"太大",则可用空间和所需空间之间的差,应为正数。

#include<stdio.h>
void main() {
// Declare variables and set initial values
int length, width, n, area, square;

// Print new values
printf("nEnter room length:");
scanf("%d", length);
printf("nEnter room width:");
scanf("%d", width);
printf("nEnter number of students:");
scanf("%d", n);

// assigning area
area = length * width;

printf("nArea is %dn", area); 
square = area - n * 10; 
if (area > n*10) {
printf("Room is too large by %d square feet", square);
}
else if (area < n*10) {
printf("Room is too small by %d square feet", square);
}
else {
printf("Room size is just right");
}
}
#include<stdio.h>
int main() {
// Declare variables and set initial values
int length, width, n, area, square;

// Print new values
printf("nEnter room length:");
scanf("%d", &length);
printf("nEnter room width:");
scanf("%d", &width);
printf("nEnter number of students:");
scanf("%d", &n);

// assigning area
area = length * width;

printf("nArea is %dn", area); 
square = area - n * 10; 
if (area > n*10) {
printf("Room is too large by %d square feet", square);
}
else if (area < n*10) {
printf("Room is too small by %d square feet", square);
}
else {
printf("Room size is just right");
}

return 0;
}`

扫描中变量前需要&运算符,以便将值存储在该变量中

例如scanf(%d,&b)

在格式说明符%d之后和变量之前使用&,因为&运算符用于获取变量的地址或获取用户输入,除了字符数组或字符串之外,在任何使用scanf的地方都可以使用。使用gets(variable_name)函数可以将字符数组或字符串作为用户的输入。例如,如果我接受你的程序,它应该是:

printf("nEnter room length:");
scanf("%d",&length);
printf("nEnter room width:");
scanf("%d",&width);
printf("nEnter number of students:");
scanf("%d",&n);
printf("n enter name : "); //datatype of Name must be String
gets(name);

相关内容

  • 没有找到相关文章

最新更新