HELP PLEASE!!!!

The file extracredit.txt contains a list of integers. Each integer is 4 digits long. (Range would be 1000 - 9999). Write a program that will read each integer, determine the sum of the digits in each integer and if the sum is even it appends a zero to the end of the integer, if the sum is odd it appends a one to the end of the integer. In other words you will be reading in a 4 digit integer and outputting a 5 digit integer that ends in either 0 or 1. You should output the 5-digit number to the console.

Example.

number read in 1234 sum of the digits 1 + 2 + 3 + 4 = 10 new number is 12340
number read in 2241 sum of the digits 2 + 2 + 4 + 1 = 9 new number is 22411
the text files reads this:

1234
1235
1236
1267
1289
1345
1289
6789
5678
3456


a function needs to be used to read the data
Last edited on
Look over tutorials about ifstream, which reads from file.
Also, tae a look at these 2 functions, the app function adds 0 or 1 to the number.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int sumofdigits(int a)
{
  int sum=0;
  while(a!=0)
  {
    sum+=a%10;
    a/=10;
  }
  return sum;
 }
int app(int &a)
{
  a*=10;
  if(sumofdigits(a)%2!=0)
  a++;
}

Also stop posting your homework here.
Last edited on
Topic archived. No new replies allowed.