Closed. This question is off-topic. It is not currently accepting answers. Learn more
想改进这个问题吗?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分隔符%dint存储为str类型,我假设它是某种struct类型。如果是的话,这不是办法。您必须将信息分别存储到struct的每个部分中。或者将类型str更改为int。这可能是while循环不发生的原因,因为您正试图将intstr进行比较:
while(RandomInt <= Deudores);  // Deudores is a str

然后,您通过两次调用scanf()来读取两次信息,但您只是比较第二次得到的信息。此外,第一次阅读时,使用的分隔符是无效的。应该是&c此外,您使用无效的类型创建上面的%c变量,并且在代码的任何地方都不给它值,因此您不能在str Fabri语句中进行比较:
scanf("&c",&WhoOwes);
if(scanf("%c",&WhoOwes)==Fabri)

由于您使用的是字符分隔符str,因此应该将if%c声明为WhoOwes类型,以便具有一致的逻辑,尽管技术上不需要它,因为Fabrichar存储可互换的信息。您还必须将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;
 }

09-30 13:36
查看更多