我正在尝试在C上编译它,但我无法看到哪里出错。
#include <stdio.h>
int verifica_quatro (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_tres (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_dois (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_grupo (int N, int M)
{
if (M == 0)
M= 100;
if (N == 0)
N= 100;
N= (N-1)/4;
M= (M-1)/4;
if (N == M)
return 1;
else
return -1;
}
int main(void)
{
int V, N, M, r;
int valor = -1;
int cont = 4;
scanf("%d %d %d", &V, &N, &M);
while !(M==0 && N==0 && V==0) {
while (M>=10000) {
M= M/10;
}
while (N>=10000) {
N= N/10;
}
while (cont>0 && valor<0){
if (cont == 4){
r = verifica_quatro(N,M);
valor = V*2500*r;
}else if(cont == 3){
N = N/10;
M = M/10;
r = verifica_tres(N,M);
valor = V*510*r;
}else if(cont == 2){
N = N/100;
M = M/100;
r = verifica_dois(N,M);
valor = V*77*r;
}else if(cont == 1){
N = N/100;
M = M/100;
r = verifica_grupo(N,M);
valor = V*34*r;
}
cont--;
}
}
if (valor<0)
valor = 0;
printf ("%d\n", valor);
printf ("Digite M, N e V");
scanf ("%d %d %d", &M, &N, &V);
}
return 0;
}
答案 0 :(得分:1)
这是您成功编译的代码。
N=1000
在你的外部while循环中你写
while!(M == 0&amp;&amp; N == 0&amp;&amp; V == 0)
它应该是语法错误
while(!(M == 0&amp;&amp; N == 0&amp;&amp; V == 0))
#include <stdio.h>
int verifica_quatro (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_tres (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_dois (int N, int M)
{
if (M==N)
return 1;
else
return -1;
}
int verifica_grupo (int N, int M)
{
if (M == 0)
M= 100;
if (N == 0)
N= 100;
N= (N-1)/4;
M= (M-1)/4;
if (N == M)
return 1;
else
return -1;
}
int main(void)
{
int V, N, M, r;
int valor = -1;
int cont = 4;
scanf("%d %d %d", &V, &N, &M);
while (!(M==0 && N==0 && V==0)) //Here a problem with ()
{
while (M>=10000)
{
M= M/10;
}
while (N>=10000)
{
N= N/10;
}
while (cont>0 && valor<0)
{
if (cont == 4)
{
r = verifica_quatro(N,M);
valor = V*2500*r;
}
else if(cont == 3)
{
N = N/10;
M = M/10;
r = verifica_tres(N,M);
valor = V*510*r;
}
else if(cont == 2)
{
N = N/100;
M = M/100;
r = verifica_dois(N,M);
valor = V*77*r;
}
else if(cont == 1)
{
N = N/100;
M = M/100;
r = verifica_grupo(N,M);
valor = V*34*r;
}
cont--;
}
}
if (valor<0)
valor = 0;
printf ("%d\n", valor);
printf ("Digite M, N e V");
scanf ("%d %d %d", &M, &N, &V);
//} This should be deleted
return 0;
}
之前的大括号是额外的,它应该被删除。
答案 1 :(得分:0)
中缺少一组括号
while !(M==0 && N==0 && V==0)
以这种方式修复:
while (!(M==0 && N==0 && V==0))
或者更令人困惑的是:
while (M|N|V)
另外:缩进你的代码,每个级别有4个空格,没有TABS!
答案 2 :(得分:0)
这两行最后没有任何功能。加上chqrlie说的......
return 0;
}