我的问题是: 编写一个程序,在用户范围(1-99)之间输入一个数字作为输入,并使用多个开关情况将数字转换为单词。如果用户按Enter键,则程序应退出。 [在此输入图像说明] [1]
enter code here
enter code here
我对此问题的解决方案如下,但我没有正常工作,因为字符变量一个得到一个字符。请好好看看&帮我找到解决这个问题的方法。 在这里输入代码
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char a='a';
cout<<"Enter a number: ";
a=getche();
switch(a)
{
case 1: cout<<"One"; break;
case 2: cout<<"Two"; break;
case 3: cout<<"Three"; break;
case 4: cout<<"Four"; break;
case 5: cout<<"Five"; break;
case 6: cout<<"Six"; break;
case 7: cout<<"Seven"; break;
case 8: cout<<"Eight"; break;
case 9: cout<<"Nine"; break;
case 10: cout<<"Ten"; break;
case 11: cout<<"Eleven"; break;
case 12: cout<<"Twelve"; break;
case 13: cout<<"Thirteen"; break;
case 14: cout<<"Fourteen"; break;
case 15: cout<<"Fifteen"; break;
case 16: cout<<"Sixteen"; break;
case 17: cout<<"Seventeen"; break;
case 18: cout<<"Eighteen"; break;
case 19: cout<<"Nineteen"; break;
case 20: cout<<"Twenty"; break;
case 21: cout<<"Twenty One"; break;
case 22: cout<<"twenty two"; break;
case 23: cout<<"twenty three"; break;
case 24: cout<<"twenty four"; break;
case 25: cout<<"twenty five"; break;
case 26: cout<<"twenty six"; break;
case 27: cout<<"twenty seven"; break;
case 28: cout<<"twenty eight "; break;
case 29: cout<<"twenty nine "; break;
case 30: cout<<"thirty"; break;
case 31: cout<<"thirty one"; break;
case 32: cout<<"thirty two"; break;
case 33: cout<<"thirty three"; break;
case 34: cout<<"thirty four"; break;
case 35: cout<<"thirty five"; break;
case 36: cout<<"thirty six"; break;
case 37: cout<<"thirty seven"; break;
case 38: cout<<"thirty eight"; break;
case 39: cout<<"thirty nine"; break;
case 40: cout<<"forty"; break;
case 41: cout<<"forty one"; break;
case 42: cout<<"forty two"; break;
case 43: cout<<"forty three"; break;
case 44: cout<<"forty four"; break;
case 45: cout<<"forty five"; break;
case 46: cout<<"forty six"; break;
case 47: cout<<"forty seven"; break;
case 48: cout<<"forty eight"; break;
case 49: cout<<"fourty nine"; break;
case 50: cout<<"fifty"; break;
case 51: cout<<"fifty one"; break;
case 52: cout<<"fifty two"; break;
case 53: cout<<"fifty three"; break;
case 54: cout<<"fifty four"; break;
case 55: cout<<"fifty five"; break;
case 56: cout<<"fifty six"; break;
case 57: cout<<"fifty seven"; break;
case 58: cout<<"fifty eight"; break;
case 59: cout<<"fifty nine"; break;
case 60: cout<<"sixty"; break;
case 61: cout<<"sixty one"; break;
case 62: cout<<"sixty two"; break;
case 63: cout<<"sixty three"; break;
case 64: cout<<"sixty four"; break;
case 65: cout<<"sixty five"; break;
case 66: cout<<"sixty six"; break;
case 67: cout<<"sixty seven"; break;
case 68: cout<<"sixty eight"; break;
case 69: cout<<"sixty nine"; break;
case 70: cout<<"seventy"; break;
case 71: cout<<"seventy one"; break;
case 72: cout<<"seventy two"; break;
case 73: cout<<"seventy three"; break;
case 74: cout<<"seventy four"; break;
case 75: cout<<"seventy five"; break;
case 76: cout<<"seventy six"; break;
case 77: cout<<"seventy seven"; break;
case 78: cout<<"seventy eight"; break;
case 79: cout<<"seventy nine"; break;
case 80: cout<<"eighty"; break;
case 81: cout<<"eighty one"; break;
case 82: cout<<"eighty two"; break;
case 83: cout<<"eighty three"; break;
case 84: cout<<"eighty four"; break;
case 85: cout<<"eighty five"; break;
case 86: cout<<"eighty six"; break;
case 87: cout<<"eighty seven"; break;
case 89: cout<<"eighty nine"; break;
case 90: cout<<"ninety"; break;
case 91: cout<<"ninety one"; break;
case 92: cout<<"ninety two"; break;
case 93: cout<<"ninety three"; break;
case 94: cout<<"ninety four"; break;
case 95: cout<<"ninety five"; break;
case 96: cout<<"ninety six"; break;
case 97: cout<<"ninety seven"; break;
case 98: cout<<"ninety eight"; break;
case 99: cout<<"ninety nine"; break;
case '\n': break;
default:
cout<<"Try Again!";
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
而不是(它读取单个字符而不是数字)
char a='a';
cout<<"Enter a number: ";
a=getche();
你可以简单地从流中读取整数:
int a;
cout<<"Enter a number: ";
cin>>a;