试着在这里弄清楚我的C代码出错了什么。最后两个printf
调用是要求类型说明符,我不知道要给它什么。其他方面没有这个问题。任何帮助表示赞赏!
编辑程序执行多个数学函数,并且所讨论的两条打印线应该打印其中两个方程的结果。第一个应该打印用户输入的两个数字的剩余部分,第二个printf应该打印出将两个数字相加的答案,将其乘以第一个数字,然后除以第二个数字。这两个printf行都给出了E0079的错误,期望一个类型说明符。
编辑2:通过更改项目的SDK包以及在询问用户输入数字后进行计算来解决此问题。吉米的格式提示也有助于修复它。非常感谢所有帮助过你的人。
#include <stdio.h>
#include <stdlib.h>
main(void) {
int digit1; //First digit user gives
int digit2; //Second digit user gives.
int product; //The result of the two user given numbers multiplied.
int cube; //The result of cubing the second number.
int remainder; //The remainder of dividing the two given numbers.
int tooManySteps; //The result of adding the two given numbers together, multiplying it by the first given number, dividing by the second number.
product = digit1 * digit2;
cube = digit2 * digit2 * digit2;
remainder = digit1 % digit2;
tooManySteps = (digit1 + digit2) * digit1 / digit2;
printf("Hi there, want me to do some cool math for you? Great! Just give me a number please.");
scanf("%d", &digit1);
printf("Cool! Now just give me one number.");
scanf("%d", &digit2);
printf("Your numbers multiplied together give you %d \n", product);
printf("Now the cube of the second number you gave is %d \n", cube);
printf("If you were to divide your two numbers together your remainder would be %d\n", remainder);
printf("Now we'll get really crazy, if you were to add your two numbers, multiply them by the first number you gave and divide by the second number you gave, you would get %d\n", tooManySteps);
}
答案 0 :(得分:0)
我真的认为这是一个糟糕的问题。但我仍然为你纠正代码。
int main(void)
{
int digit1; //First digit user gives
int digit2; //Second digit user gives.
int product; //The result of the two user given numbers multiplied.
int cube; //The result of cubing the second number.
int remainder; //The remainder of dividing the two given numbers.
int tooManySteps; //The result of adding the two given numbers together,
//multiplying it by the first given number,
//dividing by the second number.
printf("Hi there, want me to do some cool math for you? Great! "
"Just give me a number please.");
scanf("%d", &digit1);
printf("Cool! Now just give me one number.");
scanf("%d", &digit2);
product = digit1 * digit2;
cube = digit2 * digit2 * digit2;
remainder = digit1 % digit2;
tooManySteps = (digit1 + digit2) * digit1 / digit2;
printf("Your numbers multiplied together give you %d \n", product);
printf("Now the cube of the second number you gave is %d \n", cube);
printf("If you were to divide your two numbers together your "
"remainder would be %d\n", remainder);
printf("Now we'll get really crazy, if you were to add your two numbers, "
"multiply them by the first number you gave and divide by the second"
" number you gave, you would get %d\n",
tooManySteps);
return 0;
}