我不太清楚我的问题是什么。我的代码中不断出现错误。
错误:运行时检查失败:使用的变量未初始化。: 警告 C4700: 使用了未初始化的局部变量 'b'
有人可以帮我解决这个问题吗?任何帮助将不胜感激。我正在使用 Visual Studio 作为 C 的编译器,我是它的初学者,这是一项任务。如果我输入“int b;”,我不明白为什么我会一直遇到这个问题 在程序的开头。该变量不会被初始化吗?
这是代码:
#include <stdio.h>
//Create a program that asks the user to enter a number until the user enters a -1 to stop
int main()
{
int b;
//as long as the number is not -1, print the number on the screen
while(b!=-1) {
printf("Hello there! would you please enter a number?");
scanf(" %d",&b);
//as long as the number is not -1, print the number on the screen
if(b!=-1){
printf("Thank you for your time and consideration but the following %d you entered wasn't quite what we expected. Can you please enter another?\n",b);
//When the user enters a -1 print the message “Have a Nice Day :)” and end the program
}else {
printf("Have a Nice Day :), and see you soon\n");
}
}
return 0;
}