0
只要用戶在序列中輸入它們(奇數,偶數,奇數(..)),我想製作一個簡單的程序,用於求和用戶輸入的整數,只要求和低於100.這是我的代碼。C - 多個左值錯誤
#include <stdio.h>
int check_odd(int x)
{
int i = x - 1;
int o;
for (i = x - 1; i > 1; i--)
{
if (x % i = 0)
{
o = 1;
break;
}
}
if (o != 1)
{
o = 0;
}
return o;
}
int check_even(int x)
{
int i;
i = x/2;
if (i * 2 = x)
{
x = 1;
}
else x = 0;
return x;
}
int main()
{
int a;
int b;
int s = 0;
while (s < 100)
{
while (1 = 1)
{
printf("Enter an odd number\n");
scanf("%d , &a");
b = check_odd(a);
if (b = 1)
{
s = s + a;
printf("Current sum equals %d , &s\n");
break;
}
printf("Entered number is incorrect. Try again.\n");
}
while (1 = 1)
{
printf("Enter an even number\n");
scanf("%d , &a");
b = check_even(a);
if (b = 1)
{
s = s + a;
printf("Current sum equals %d , &s\n");
break;
}
printf("Entered number is incorrect. Try again.\n");
}
}
printf("Sum equals $d , &s\n");
}
現在,我得到線
if (x % i = 0)
if (i * 2 = x)
和
while (1 = 1)
我做了什麼錯,爲什麼在地球上1 = 1的語句給我一個左值誤差左值錯誤?對於延遲代碼也很抱歉,剛開始。