I have an issue with this program and I'm almost positive that I am going about it all wrong.
The idea of the program is to take an integer (well call this N = Ak,Ak-1,Ak-2...A0), and take the sum of the numbers (well call this S = A0 - A1 + A2 - .... +(-1)k Ak), and as it is known that N is divisible by 11 if and only if S is divisible by 11. I have the structure correct (at least I hope so), but I have that strange feeling I'm going about this all wrong.
// include statement(s).
#include <iostream>
// using namespace statement.
using namespace std;
// Declare named constants, if necessary.
int main()
{
// Declare named variables, if necessary.
int PosInt, temp, sum;
// Executable statement(s).
cout << "Please Enter a Positive Integer ";
cin >> PosInt;
cout << endl;
temp = PosInt;
sum = 0;
do
{
sum = sum + PosInt % 10;
PosInt = PosInt / 11;
}
while (PosInt > 0);
cout << "The sum of the digits = " << sum << endl;
if (sum % 11 == 0)
cout << temp << " is divisible by 11" << endl;
else
cout << temp << " is not divisible by 11" << endl;
return 0;
}
Any help/guidance in the right direction is greatly appreciated!

New Topic/Question
Reply




MultiQuote




|