Question: Write a program, spHWrepetition.cpp , that will sum the digits of positive integers. The numbers should be read from the file spHWrepetition.txt (You should create
Write a program, spHWrepetition.cpp, that will sum the digits of positive integers.
The numbers should be read from the file spHWrepetition.txt (You should create this file and place several lines of integers as well as a sentinel of -1 into it.).
Each multi-digit number should be converted to a single integer and mathematical means should be employed to separate each digit.
Store the numbers and the sums of their digits in the file spHWoutput.txt, such that each line consists of a number followed by a colon (':') followed by the sum of its digits.
As an example, if the file spHWrepetition.txt contains
987 12345 7685 1001 -1
then the program should produce and store the following in spHWoutput.txt.
| The output of your program should look exactly like this. Data values may differ. |
987:24 12345:15 7685:26 1001:2
Be sure to close both the input file and the output file when you run out of data.
I am learning C++ and while and for statement now.
Please do not use over while and for statements.
Always thank you for your helping.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
