1. ## Novice needs help

The following is my the program I am suppose to do:

A program that uses a sentinel controlled loop to inputs
5 digits of a 5 digit number (no spaces will appear between
the digits) and then prints the sum of the digits. For example,
the input value 12345 should have a sum of 15 (1+2+3+4+5).

The sentinel value is the newline character which should be
is '\n'.

My problems are as follows: I do not know how to convert from ASCII to a numerical value, and I am not exactly sure how to use a sentinel loop.

The following is what I have so far.
Any help explaining my problems would be appreciated.

________________________________________________
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
int digit;
int sum=0;

cout << "Enter a five digit number:";
digit = cin.get();
cout << digit<<"+";
digit = cin.get();
cout << digit<<"+";
digit = cin.get();
cout << digit<<"+";
digit = cin.get();
cout << digit<<"+";
digit = cin.get();
cout << digit;

sum = sum+digit;

cout << "The sum is: " << sum << endl;

return 0;
}

2. Your compiler will convert literal chars (like '\n') to the numerical equivalent. To see the actual numerical values, you can google for the ASCII chart.

Code:
```int main()
{
int sentinal = '\n';
int digit = 1;
int sum=0;

cout << "Enter the numbers to add:";

while( (digit = cin.get() ) != sentinal)
{
if(digit != ' ')
{
sum = sum+digit;
}

}

cout << "The sum is: " << sum << endl;

cin.get();  // pause screen

return 0;
}```

3. ## Still doesn't work

I tried what you have suggested, yet my results are still the same. The addition is still not converting, so the result (if I type 12345) is 255 not 15.

Also, I want to make sure I grasp the concept of the sentinel loop. If I understand correctly, I am assigning \n as the value so as long as \n is not input it will keep taking digits.

Thank you

4. Sorry about that. The problem is, when the user enters '1' for instance, this has the corresponding ASCII value of 49. Hence:

49+50+51+52+53 = 255

So you must subtract 48 from each input.

And yes, you get the idea of the sentinal it seems. Note that the string.h library of functions rely on the value of zero as a sentinal.