Question: C++ program to print an amount in numerics to an amount in words upto 1 billion WITHOUT USING ARRAYS AND FUCNTIONS) ( only use while

C++ program to print an amount in numerics to an amount in words upto 1 billion WITHOUT USING ARRAYS AND FUCNTIONS) ( only use while and for loop and if else statement etc) ie: 9999999 output : ninety nine million nine hundred and ninety nine thousand nine hundred and ninety nine.

Sol101:

Here is an example C++ program to print an amount in numerics to an amount in words upto 1 billion without using arrays and functions:

#include

using namespace std;

int main() {

string ones[] = {\"\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"};

string tens[] = {\"\", \"ten\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\"};

string teens[] = {\"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"};

int amount, billions, millions, thousands, hundreds, tensDigit, onesDigit;

cout

cin >> amount;

// Separating amount into its place values

billions = amount / 1000000000;

amount %= 1000000000;

millions = amount / 1000000;

amount %= 1000000;

thousands = amount / 1000;

amount %= 1000;

hundreds = amount / 100;

amount %= 100;

tensDigit = amount / 10;

onesDigit = amount % 10;

// Printing the amount in words

if (billions > 0) {

cout

}

if (millions > 0) {

if (millions >= 100) {

cout

millions %= 100;

}

if (millions >= 10 && millions

cout

} else {

cout

}

}

if (thousands > 0) {

if (thousands >= 100) {

cout

thousands %= 100;

}

cout

}

if (hundreds > 0) {

cout

}

if (tensDigit > 0) {

if (tensDigit >= 2) {

cout

if (onesDigit > 0) {

cout

}

} else {

cout

}

} else if (onesDigit > 0) {

cout

}

if (billions == 0 && millions == 0 && thousands == 0 && hundreds == 0 && tensDigit == 0 && onesDigit == 0) {

cout

}

cout

return 0;

}

The program uses arrays to store the words for each number (ones, tens, and teens). It then takes the input amount and separates it into its place values (billions, millions, thousands, hundreds, tens, and ones). The program then prints out the amount in words using a series of if-else statements to handle the different cases for each place value. Finally, the program includes a check to handle the case of an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!