Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program ir C++ that reads several integers from an input rile (one at a

ID: 642676 • Letter: W

Question

Write a program ir C++ that reads several integers from an input rile (one at a time), and displays the value between O to 999 (o? each one) in words. If the number is negative, negate it to get the poactive. 5top when you get to the end or the file. You MUST use an Input tile, while loop and functions with a switch statement in each (one to print the hundreds digit in words, one to print the the tens digit in words, one to print the ones digit in words). Hints: get the ones digit using ib operator (save it in a local mt variable), get the tens digit by dividing by 10 and % 10 (save it in another local int variable), get the ones digit (similar way as tens), and save it in another local int variable.

Explanation / Answer

#include <stdio.h>

int main()

{

      int count = 0, num = 0, remainder = 0, sum = 0, stop = 0;

    

      while(stop != -1)

      {

            printf("Enter an integer: ");

            scanf_s("%d", & num);

            // test the num == 0?

            printf(" After operation: ");

            printf("remainder num ");

            printf("--------- --- ");

            while(num != 0)

            {

                  // get the remainder (digits) by dividing by 10

                  remainder = num % 10;

                  // sum up the remainder

                  sum = sum + remainder;

                  // divide the number by 10, next integer part

                  // ...10000, 1000, 100, 10, 0

                  num = num / 10;

                  // let see current value of num and remainder...

                  printf("%d        %d ", remainder, num);

            }

            printf(" ");

            // print the sum of the digits...

            printf("The sum of digits is %d ", sum);

            // reset sum to 0, for next test

            sum = 0;

            printf("More? -1 to stop, other to continue: ");

            scanf_s("%d",&stop);

      }

      return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote