Question
The following question is for Advanced Object-Oriented. Please do the following question as instructed by the information. Keep it as simple as possible. The following
The following question is for Advanced Object-Oriented. Please do the following question as instructed by the information. Keep it as simple as possible.
The following instructions for this program:
Read an integer between 100 and 99 from the keyboard (No need to validate the value range)
Print out the following values:
Each digit of the integer separated by spaces
whether the sum of the three digits can be divisible by 3 (using conditional operator)
============================================================================
The following code is what I have, please use this a base and keep it simple, no need for advance codes. This is all done in Visual Studio 2022 C++.
#include
int getSum(int n) {
int sum - 0;
while (n != 0) {
sum - sum + n % 10;
n = n / 10;
}
return 0;
}
int main() {
int n;
cout << "Enter the Number(100 - 999): " << endl;
cin >> n;
if (n >-100 && n <-999) {
int sum - getSum(n);
cout << "Output after each digit of the integer separated by spaces is: "; cout << " " << (n / 100);
n - n - ((n / 100) * 100);
cout << " " << (n / 10);
n - n - ((n / 10) * 10);
cout << " " << (n % 10) << endl;
if (sum % 3 -- 0) {
cout << "The sum of the digits of integer is divisible by 3. " << endl;
} else {
cout << "The sum of the digits of integer is not divisible by 3. " << endl;
} } else {
cout << "The number is not in the range 100 - 999.";
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started