Problem 1:
void sumSubnum(long int n)
{
long int sum = 0;
while (n >= 10)
{
sum = sum + n % 100;
n = n / 10;
}
cout << "The sum of the 2-digit subnumbers is " << sum << endl;
}
Problem 2:
void interact()
{
string response;
long int n;
cout << "Would you like to type a positive integer [YES or NO]?" << endl;
cin >> response;
while (response == "YES")
{
cout << "Please type a positive integer: ";
cin >> n;
sumSubnum(n);
cout << "Would you like to type a positive integer [YES or NO]?" << endl;
cin >> response;
}
}
Problem 3:
40 - 32 * 5 / 9 = 40 - 160 / 9 = 40 - 17 = 23If we type 40 in response to the second prompt from the program, the answer does not change much - the expression evaluates in the same way to 23.0.
(40 - 32.0) * 5 / 9 = 8.0 * 5 / 9 = 40.0 / 9 = 4.4444
(8 + 4) / 2 * 2 = 12 / 2 * 2 = 6 * 2 = 12The other expression (8 - 4) / 2 * 2 evaluates in a similar manner to 4.