You are on page 1of 2

#include <iostream>

#include <string>

using namespace std;

//int N=9; //

///////////////////////////// global lly declared


arrays ////////////////////////////////////////////////////////////////////////
/////
string F10nu[] = { "one" , "two", "three" , "four" , "five" , "six" , "seven" ,
"eight" , "nine"};
string F_ten_20[] = { "eleven" , "twelve" , "thirteen" , "fourteen" ,
"fifteen" , "sixteen" , "seventeen" , "eighteen" , "nineteen" };
string F_mult10[] = { "twenty" , "thirty" , "forty" , "fifty" , "sixty" ,
"seventy" , "eighty" , "ninety" };
string last[] = { "ten" ,"twenty" , "thirty" , "forty" , "fifty" , "sixty" ,
"seventy" , "eighty" , "ninety" };
string Flast[] = { "hundred" , "and" , "thousand" };
string koo[]
={ "one" ,"two","three","four","five","six","seven","eight","nine","ten","eleven","
twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"
};
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

int count_char(string to_count);


int sum_one_ninteen();
int sum_20_99();
int sum_100_999();
int sum_last();

///////////////////////////////////////////////////////////////////////////////////
//////////////////
int main(){
cout<<"There are "<<sum_one_ninteen() + sum_20_99() + sum_100_999() +
sum_last()<< " characters in total" <<endl;
}
///////////////////////////////////////////////////////////////////////////////////
//////////////////
/////////// below is the function that counts the number of char in a
string //////////////////////
int count_char(string to_count){
int countt = 0;
for(int i = 0; ; i++){
countt++;
if(to_count[i] == '\0'){
break;
}
}
return countt-1;
}
///// it sums from twenty to
99 //////////////////////////////////////////////////////////////////
int sum_one_ninteen(){
int sum = 0;
for(int i=0; i<19; i++){
sum+= count_char(koo[i]);
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/////////////

///////////////////////////////////////////////////////////////////////////////////
////////
///////////below is the function that
sum_20_99 //////////////////////////////////////
int sum_20_99(){
int sum = 0;
for(int i=0; i < 8;i++){
sum+=count_char(F_mult10[i]);
for(int j= 0 ; j<9 ; j++){
sum+=(count_char(F_mult10[i]) + count_char(F10nu[j])) ;
}
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/////
///////////below is the function that sums from 100 to
999 //////////////////////////
int sum_100_999(){
int sum =0;
for(int i = 0 ; i<9; i++){
sum+=(count_char(F10nu[i]) + 9);
for(int j = 0 ; j<19 ;j++){
sum+=(count_char(F10nu[i]) +9 + count_char(koo[j]));
if(j <8){
for(int r=0 ; r<9 ; r++){
sum+=(count_char(F10nu[i]) +10+ count_char(F_mult10[j]) +
count_char(F10nu[r]));
}
}

}
}
return sum;
}
///////////////////////////////////////////////////////////////////////////////////
/

////// the function tha sums the mutiple of ten ////////////////////////


int sum_last(){
int sum=0;
for(int i=0; i <9 ; i++){
for(int j=0; j<9; j++){
sum +=(count_char(F10nu[i]) + 10 + count_char(last[j]));
}
}
return sum + count_char(Flast[2]) + count_char(F10nu[0]);
}
//////////////////////////////////////////////////////////////////////////////

You might also like