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
the last character retrieved from the input stream. It's value
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;
}