Hi. How do I write a program that sums the digits of a 4-digit number? I have a program that works, but you have to input the digits separately. Can anyone help or possibly explain what I'm doing wrong? My professor told us as a hint to use the modulus sign (%), but i don't know how I would use that here. My code so far is below:
Code:
#include <iostream>
using namespace std;
int main(void)
{
int iA = 0;
int iB = 0;
int iC = 0;
int iD = 0;
int iTotal = 0;
cout << "Please enter a four-digit number." << endl;
cin >> iA >> iB >> iC >> iD;
iTotal = iA + iB + iC + iD;
cout << "The sum of the digits is " << iTotal << endl;
return 1;
}
Comment