Closed. This question is off-topic. It is not currently accepting answers. Learn more。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
5年前关闭。
这是代码,它忽略了while,我不知道为什么,只要输入第一个printf的值,它就应该从while开始
谢谢!小时
到(删除分号):
此外,在
此外,什么类型是
您正在使用
然后,您通过两次调用
由于您使用的是字符分隔符
但是,在代码的末尾有一个语句:
这将不起作用,因为您缺少用于打印
将该行更改为:
由于您在计算中使用的是
你的程序应该是这样的:
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
5年前关闭。
这是代码,它忽略了while,我不知道为什么,只要输入第一个printf的值,它就应该从while开始
#include <stdio.h>
int main()
{
str WhoOwes,Fabri,Alen,Amilcar,Maxi,Lolo;
int RandomInt=0,Deudores;
printf("How many people owes?:");
scanf("&d",&Deudores);
while(RandomInt <= Deudores);
{
printf("who owes?:");
scanf("&c",&WhoOwes);
if(scanf("%c",&WhoOwes)==Fabri)
{
Fabri= Fabri+1;
printf("Fabri debe $",Fabri*4);
}
}
return 0;
}
谢谢!小时
最佳答案
更改:
while(RandomInt <= Deudores);
到(删除分号):
while(RandomInt <= Deudores)
此外,在
scanf
中使用的分隔符应该是%d
而不是&d
。此外,什么类型是
str
?您正在使用
scanf
分隔符%d
将int
存储为str
类型,我假设它是某种struct
类型。如果是的话,这不是办法。您必须将信息分别存储到struct
的每个部分中。或者将类型str
更改为int
。这可能是while循环不发生的原因,因为您正试图将int
与str
进行比较:while(RandomInt <= Deudores); // Deudores is a str
然后,您通过两次调用
scanf()
来读取两次信息,但您只是比较第二次得到的信息。此外,第一次阅读时,使用的分隔符是无效的。应该是&c
此外,您使用无效的类型创建上面的%c
变量,并且在代码的任何地方都不给它值,因此您不能在str Fabri
语句中进行比较:scanf("&c",&WhoOwes);
if(scanf("%c",&WhoOwes)==Fabri)
由于您使用的是字符分隔符
str
,因此应该将if
和%c
声明为WhoOwes
类型,以便具有一致的逻辑,尽管技术上不需要它,因为Fabri
和char
存储可互换的信息。您还必须将int
变量初始化为一些char
值。但是,在代码的末尾有一个语句:
printf("Fabri debe $",Fabri*4);
这将不起作用,因为您缺少用于打印
Fabri
值的分隔符。将该行更改为:
printf("Fabri debe %d$",Fabri*4); // add the %d delimiter to print the actual value
由于您在计算中使用的是
char
,因此您可能应该将所有变量声明为Fabri*4
,并使用Fabri
分隔符读取它们,而不是int
。你的程序应该是这样的:
#include <stdio.h>
int main()
{
int WhoOwes, Fabri, Alen, Amilcar, Maxi, Lolo; // these are int types not str types
int RandomInt = 0, Deudores;
Fabri = 5; // initialize Fabri to some value that can be used for comparisons
printf("How many people owes?:");
scanf("%d",&Deudores);
while(RandomInt <= Deudores);
{
printf("who owes?:");
scanf("%d",&WhoOwes); // use
if(WhoOwes == Fabri) // use what you scanned the first time to compare to Fabri
{
Fabri= Fabri+1;
printf("Fabri debe %d$",Fabri*4); // add the int delimiter %d to actually print the money amount
}
}
return 0;
}