我的程序假设提示用户输入数字 1-12 并输出相应的月份。好的,我知道我错过了这个程序的一个非常重要的部分,但我知道我正在努力弄清楚该使用什么。我是否需要一个包含所有月份名称的字符串?此外,我知道我需要在 cout<<"the month is"<< 之后需要放一些东西,所以答案会打印出来,但我不确定现在是什么。我也认为我需要有 int month= 的东西,但不确定它应该是 1-12 还是月份名称。这是我编辑的程序,它正在运行,但现在它有一个调试错误,变量“月”正在使用而没有被初始化。这意味着什么?
#include <iostream>
#include <string>
using namespace std;
char chr;
int main()
{
int month;
cout<<"Enter a number from 1-12.";
if (month ==1)
cout<<"January";
else if (month==2)
cout<< "February";
else if (month==3)
cout<<"March";
else if (month==4)
cout<<"April";
else if (month==5)
cout<<"May";
else if (month==6)
cout<<"June";
else if (month==7)
cout<<"July";
else if (month==8)
cout<<"August";
else if (month==9)
cout<<"September";
else if (month==10)
cout<<"October";
else if (month==11)
cout<<"November";
else if (month==12)
cout<<"December";
else if (month>12)
cout<<"Sorry I need a number from 1-12."<<endl;
else if(month<=12)
cout<< "The month is "<<month;
cin>>chr;
return 0;
}