samedi 17 avril 2021

C++ program in which, read a six digit integer as input from user and output each of its digit in words by for/ While loop

/Write a C++ program in which, read a six digit integer as input from user and output each of its digit in words by using loop./

#include <iostream>
using namespace std;
int main()
{
    int number, last_number, count = 0;
    cout << "Please enter a six digit number:" << endl;
    cin >> number;

    while (count < 6)
    {

         last_number = number % 10;


        if (last_number == 0)
            cout << "Zero ";
        else if (last_number == 1)
            cout << "One ";
        else if (last_number == 2)
            cout << "Two ";
        else if (last_number == 3)
            cout << "Three ";
        else if (last_number == 4)
            cout << "Four ";
        else if (last_number == 5)
            cout << "Five ";
        else if (last_number == 6)
            cout << "six ";
        else if (last_number == 7)
            cout << "Seven ";
        else if (last_number == 8)
            cout << "Eight ";
        else if (last_number == 9)
            cout << "Nine ";


        number = number / 10;
        count++;


    }
    cout << endl;
    return 0;

}

when i run the program it output opposite values e.g I want to print 123456 instead of outputting one two three four five six it outputs six five four three two one. How do i fix this?

Aucun commentaire:

Enregistrer un commentaire