Write a C program that reads each character from a user inpu
Write a C++ program that reads each character from a user input, extracts the character if it is a digit, and calculates the sum of all the digits. The program stops reading the user input when the new line character ‘\ ’ is encountered. For the output of the program, you should print each digit extracted from the user input and the sum of all the digits.
---use this:
-----the output looks like:
Thank you very much!!
Solution
#include<iostream.h>
#include<conio.h>
void main()
{ int value, sum = 0;
char c;
cout<<\"Enter the characters\";
do
{
cin>>c;
if( c>=\'0\' && c<=\'9\')
{ value = int(c);
sum = sum + value;
}
}while(c!=\'\ \');
}
