我似乎无法在代码中找到问题。似乎一切都很好。我应该输出两个整数的积和。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
main() {
int number1, number2, productResult, sumResult;
printf("Enter first number: ");
scanf("%i", &number1);
productResult = number1 * number2;
printf("Enter second number: ");
scanf("%i", &number2);
sumResult = number1 + number2;
printf("The product is: %i \n", productResult);
printf("The sum is:s %i \n", sumResult);
system("pause");
} // end of main
最佳答案
我建议您要么获得更好的编译器,要么倾听来自编译器的警告:
blah.c:5:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main() {
^
blah.c:10:31: warning: variable 'number2' is uninitialized when used here [-Wuninitialized]
productResult = number1 * number2;
^~~~~~~
blah.c:6:25: note: initialize the variable 'number2' to silence this warning
int number1, number2, productResult, sumResult;
^
= 0
2 warnings generated.
在要求用户提供其内容之前,您正在使用
number2
。关于c - 如何使此代码运行?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39442867/