Help with coding in C++ If the numbers 1 to 5 are written out in words - one, tw
ID: 3684481 • Letter: H
Question
Help with coding in C++
If the numbers 1 to 5 are written out in words - one, two three, four, five - then the number of letters used in total is 3 + 3 + 5 + 4 + 4 = 19 letters
If all the numbers from 1 to 1000 (one thousand),inclusive, were written out in words, how many letters would be used?
Solution must include:
a) include at least two functions where:
i) at least one function has to take in a parameter
ii) at least one function has to return a value
b) print out all numbers from 1 to 1000 as words
c) print out the toal number of letters
Don't count spaces or hyphens as characters... but count 'and' as three letters. Ex) 101 - One hundred and letters.
Question is testing ability to write functions and pass values into other functions and then print them out. I know you should use word.length() to help with your counting for loop.
Thank you!!
Explanation / Answer
#include<conio.h>
#include<iostreram>
using namespace std;
void numword(int);
void numword1(int);
main() {
int num,temp,i,digit,count=0,last,h,arr[];
string word,a[];
int n;
cout << “Enter Number:’;
cin>> num;
cout<<”Enter size of array”;
cin >> n;
for(i=0;i<=n;i++) {
arr[i] = num;
}
if(num>1000) {
cout<<”Out of range”;
getch();
exit(0); }
if (num == 0) {
cout <<”Zero”;
getch();
exit(0); }
temp = num;
digit = temp%10;
last = digit;
num = temp/10;
last = (digit*10) + last;
num = num/10;
digit = num%10;
h = digit;
num = num/10;
digit = num%10;
t = digit;
num = num/10;
digit = num%10;
t = (digit*10) + t;
while(temp!=0) {
temp = temp/10;
count ++; }
while(num) {
for(i=0;i<=n;i++) {
cout<< “ The number in words is: “;
if(digit ==4) {
word = numword1(t);
cout<<”Thousand”;
} else if(digit ==3) {
word = numword1(h); }
word = numword1(last);
getch();
return 0;
a[i] = word; } } }
void numword(int num) {
switch(num) {
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<< “Ninteen”; break;
}
return; }
void numword1(int num) {
if(num>=90) {
cout << “Ninety”;
numword(num-90); }
else if(num>=80) {
cout << “Eighty”;
numword(num-80); }
else if(num>=70) {
cout << “Seventy”;
numword(num-70); }
else if(num>=60) {
cout << “Sixty”;
numword(num-60); }
else if(num>=50) {
cout << “Fifty”;
numword(num-50); }
else if(num>=40) {
cout << “Fourty”;
numword(num-40); }
else if(num>=30) {
cout << “Thirty”;
numword(num-30); }
else if(num>=20) {
cout << “Twenty”;
numword(num-20); }
else numword(num);
return;
} }
for(i=0;i<=n;i++)
cout<< “The numbers are:” <<arr[i] <<end1;
while(num) {
for(i=0;i<=n;i++) {
cout<<”The words are:”<<a[i]<<end1;
total + = word.length(a[i]);
}
cout<<” Total count :”<< total <<end1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.