我寫一個C++程序,數字轉換爲文本。錯誤與數字轉換爲文本
我有兩個問題(編輯:只是一個現在):
第一個問題是,該方案只能從20-99人寫出來的數字爲1-19正確的,一切都如我我寫了34個例子,我得到的答案是三十而不是三十四,因爲它應該是。三十之後,它只是出現錯誤,程序關閉。 [問題修正]
的第二個問題是,我希望我能0-999,而不是隻有99,但林不知道之間寫數字如何做到這一點
#include <iostream> #include <string> using namespace std; int main() { int num, Ldight, Rdight; string ones[] = {"zero", "one", "two", "three", "four", "five","six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"}; string tens[] = {"twenty","thirty","fourty","fifty", "sixty","seventy","eighty", "ninety"}; cout << "Pick a number between 1-99: "; cin >> num; if(num <= 0) { cout << "ERROR!" << endl; } else if (num >= 0 && num <= 19) { cout << "Your number is: " << ones[Rdight] ; } else if (num >=20 && num <=99) { Rdight = num % 10; Ldight = num/10; cout << "Your number is: " << tens[Ldight - 2] << ones[Rdight]; } return 0; }
請在發佈前正確格式的代碼。這將幫助我們幫助你。 – m0skit0