我两个月前开始学习计算机科学。我需要这方面的帮助。
编译器给了我这个警告,我的程序没有给出数字。
Lab4Problem3.cpp:202:11:警告:多字符字符常量 [-Wmultichar]
Lab4Problem3.cpp:202:26:警告:字符常量对其类型来说太长 [默认启用]
Lab4Problem3.cpp:在函数“int main()”中:
Lab4Problem3.cpp:27:16:警告:'std::string word_number(std::string, std::string)' 的地址将始终评估为 'true' [-Waddress]
Lab4Problem3.cpp:29:16:警告:'std::string word_number(std::string, std::string)' 的地址将始终评估为 'true' [-Waddress]
这是我所拥有的:
#include <iostream>
#include <string>
using namespace std;
string word_number(string units, string tens);
int num_entered;
int main ()
{
char answer;
do
{
cout << "Enter the number of bottles to throw on the wall: " << endl;
cin >> num_entered;
cout << endl;
if (num_entered < 99 && num_entered >= 0)
{
while (num_entered > 0)
{
cout << word_number;
cout << " bottles of beer on the wall,\n";
cout << word_number;
cout << " bottles of beer,\n"
<< "Take one down, pass it around.\n";
num_entered--;
}
if (num_entered == 0)
cout << "Zero bottles of beer on the wall" << endl;
}
else
cout << "Invalid number!" << endl;
cout << "Do you want to try it again? (Y/N)" << endl;
cin >> answer;
} while (answer =='Y' || answer=='y');
return 0;
}
string word_number(string units, string tens)
{
int tens_number, units_number;
string result;
if (num_entered < 20)
{
if(num_entered < 10)
{
units_number = num_entered;
switch (units_number)
{
case 1:
units =="One";
break;
case 2:
units =="Two";
break;
case 3:
units =="Three";
break;
case 4:
units =="Four";
break;
case 5:
units =="Five";
break;
case 6:
units =="Six";
break;
case 7:
units =="Seven";
break;
case 8:
units =="Eight";
break;
case 9:
units =="Nine";
break;
}
return(units);
}
else
units_number = num_entered%10;
switch(units_number)
{
case 0:
units =="Ten";
break;
case 1:
units =="Eleven";
break;
case 2:
units =="Twelve";
break;
case 3:
units =="Thirteen";
break;
case 4:
units =="Fourteen";
break;
case 5:
units =="Fifteen";
break;
case 6:
units =="Sixteen";
break;
case 7:
units =="Seventeen";
break;
case 8:
units =="Eighteen";
break;
case 9:
units =="Nineteen";
break;
}
return (units);
}
else
tens_number = num_entered/10;
units_number = num_entered%10;
switch (tens_number)
{
/*case 0:
tens == "Zero";
break;*/
case 1:
tens =="Ten";
break;
case 2:
tens =="Twenty";
break;
case 3:
tens =="Thirty";
break;
case 4:
tens =="Fourty";
break;
case 5:
tens =="Fifty";
break;
case 6:
tens =="Sixty";
break;
case 7:
tens =="Seventy";
break;
case 8:
tens =="Eighty";
break;
case 9:
tens =="Ninety";
break;
}
units_number = num_entered%10;
switch (units_number)
{
case 1:
units =="One";
break;
case 2:
units =="Two";
break;
case 3:
units =="Three";
break;
case 4:
units =="Four";
break;
case 5:
units =="Five";
break;
case 6:
units =="Six";
break;
case 7:
units =="Seven";
break;
case 8:
units =="Eight";
break;
case 9:
units =="Nine";
break;
}
result = 'tens' + "-" + 'units';
return result;
}