请好起来我是一个总newby。给一个单词添加一个数字来调出一个变量
我有一个从num1到num90的变量列表(字符串)。我需要通过将一个int中的数字添加到单词num中来调用这些函数。
任务是将数字转换为'跳入C++'的单词...我可能不会以'正确'的方式进行操作,但这部分现在已经阻止了我一段时间!
我想是这样的:
#include <iostream>
#include <string>
using namespace std;
// Hard code numbers to 20 and then in tens to 90
string num1 = "one";
string num2 = "two";
string num3 = "three";
string num4 = "four";
string num5 = "five";
string num6 = "six";
string num7 = "seven";
string num8 = "eight";
string num9 = "nine";
等......多达90
int main()
{
// Break the number down into three digit blocks
int num = 0;
cout << "Please enter the number: ";
cin >> num;
while (num > 999)
{
int digit = (num % 1000);
num = ((num - digit)/1000);
//cout << digit << '\n';
//cout << num << '\n';
// For each block of numbers work out hundreds,
if (digit > 100)
{
int i = digit;
int j = (i % 100);
cout << num.append(j) << " hundred";
}
我需要发生的是被标记到存储在“J”的数word num为了调用字符串num *。
这可能吗?
你最终要像'int2words',或有什么功能?写一些输入 - >输出例子。 – Mikhail