我对下面的代码有问题
#include <stdio.h>
int main() /* Tidsberäkning YO */
{
float tid1, tid2;
printf("Tid i första åket? ");
scanf("%f", %tid1);
printf("Tid i andra åket? ");
scanf(%f", &tid2);
printf("Total Tid: %f\n", tid1+tid2);
printf(Genomsnittlig tid: %f\n", (tid1+tid2)/2);
}这是错误日志
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(6): error C2059: syntax error : '%'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): error C2143: syntax error : missing ')' before '%'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): error C2198: 'scanf' : too few arguments for call`
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): error C2001: newline in constant
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): error C2065: 'f' : undeclared identifier
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): error C2143: syntax error : missing ';' before 'string'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(8): warning C4552: '%' : operator has no effect; expected operator with side-effect
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(9): error C2146: syntax error : missing ';' before identifier 'printf'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): error C2065: 'Genomsnittlig' : undeclared identifier
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): warning C4024: 'printf' : different types for formal and actual parameter 1
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): error C2146: syntax error : missing ')' before identifier 'tid'
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): error C2017: illegal escape sequence
c:\users\shaggydoo\documents\visual studio 2010\projects\ilikecake\ilikecake\hellobro.c(10): error C2001: newline in constant发布于 2012-01-21 05:51:05
scanf(%f", &tid2);
和
printf(Genomsnittlig tid: %f\n", (tid1+tid2)/2);
缺少第一个引号。更改为:
printf("Genomsnittlig tid: %f\n", (tid1+tid2)/2);
和
scanf("%f", &tid2);
发布于 2012-01-21 05:54:09
从错误消息的第一行开始。它显示为(6): error C2059: syntax error : '%',这意味着第6行有一个与%相关的错误。
所以看看第6行(第一个scanf()行。是的,它在变量名之前有一个%,这是无效的C。删除它。
现在重新编译以删除与第一个错误相关的任何零散错误,并以相同的方式查看其余错误。
发布于 2012-01-21 05:51:46
您缺少一些",并且具有一些不必要的%。
https://stackoverflow.com/questions/8948289
复制相似问题