sách gpt4 ai đã đi

C Người mới/không hiểu vấn đề có thể là gì

In lại 作者:行者123 更新时间:2023-11-30 21:26:52 28 4
mua khóa gpt4 Nike

自从我学习 C 语言以来,我决定制作一个简单的程序,用于加、减和计算两个变量的乘积。根据用户的输入是1,2还是3来选择加/减/折叠。

#include 

int main (void) {
int a, b, c, d, e, f, g;
a=19; b=11; c=a+b; d=a-b; e=a*b; f=-1;

while (f<0 && f>3) {
printf("-press 1 to calculate the sum of a and b\n");
printf("-press 2 to calculate the difference between a and b\n");
printf("-press 3 to calculate the product of a and b\n");

scanf("%d\n",&g);
f=g;
return;
}

if (f == 1) {
printf("A+B= %ls\n", &c);
} else if (f == 2) {
printf("A-B= %ls\n", &d);
} else if (f == 3) {
printf(" A*B= %ls\n", &e);
}
trả về 0;
}

When i run the program its reads "g" and then it stops. any suggestions to why is this happening btw i also tried removing the trong khi statement.

1 Câu trả lời

我认为你的意思是下面的 while 循环

while ( f < 0 || f > 3 )
{
printf("-press 1 to calculate the sum of a and b\n");
printf("-press 2 to calculate the difference between a and b\n");
printf("-press 3 to calculate the product of a and b\n");
scanf( "%d", &g );
f = g;
}

即注意1)while循环的条件,2)删除return语句,3)删除scanf中的字符'\N',因为它是多余的。

并且在 printf 调用中删除运算符 & 并使用转换说明符 %d。

 if ( f == 1 ) {
printf(" A+B= %d\n", c) ;
}
else if ( f == 2) {
printf(" A-B= %d\n", d );
}
else if ( f == 3 ) {
printf(" A*B= %d\n",e );
}

关于C 新手/不明白问题可能是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58390689/

28 4 0
Bài viết được đề xuất: c - 不打印句子中前三个单词的指针
Bài viết được đề xuất: php - 模态弹出窗口不出现
Bài viết được đề xuất: mysql - 如果 null 在 spring 数据 jpa 查询中返回空白
Bài viết được đề xuất: c - 使用fgetc读取文件时出现垃圾字符
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com