Help for homework

Hey guys , I'm just a beginner in C++ programming. I just started couple month ago and I need your help.
I have this project for school and It would be amazing If you guys help me.
I know what the program does but I can not expain It In a professional way.



The homework is to explain what the code does:

[
#include <iostream>

int main()
{
int x, Z1, Z2, Z3, y;

std::cout << "Enter a three-digit number (between 100 and 999)";
std::cin >> x;

Z1 = x / 100;
Z2 = (x / 10) % 10;
Z3 = x % 10;
y = Z1 + Z2 + Z3;

std::cout << "Z1 = " << Z1 << std::endl;
std::cout << "Z2 = " << Z2 << std::endl;
std::cout << "Z3 = " << Z3 << std::endl;
std::cout << "Y = " << y << std::endl;

system("pause");
return 0;
}]

also i have the expain this one aswell

[
#include <iostream>

int main()
{
int x, Z1, Z2, Z3, y;

std::cout << "Enter a three-digit number (between 100 and 999)";
std::cin >> x;

Z1 = x / 100;
Z2 = (x / 10) % 10;
Z3 = x % 10;

y = (Z1 < Z3) ? Z1 * 100 + Z2 * 10 + Z3 : Z3 * 100 + Z2 * 10 + Z1;

std::cout << "X = " << x << std::endl;
std::cout << "Z1 = " << Z1 << std::endl;
std::cout << "Z2 = " << Z2 << std::endl;
std::cout << "Z3 = " << Z3 << std::endl;
std::cout << "Y = " << y << std::endl;

system("pause");
return 0;
}]
Last edited on
There is nothing here super hard, start adding comments to every line of the code.

If your not sure what it does, run the code and see what the output does.
If you have a specific question then let us know.
first one :
z1 = get the first digit of a number
z2 = get the second digit of a number
z3 = get the last digit of a number

second one :
same, except there's some sort of a conditional statement on y, if you analyse it closely you can understand what is going on .. for reference check this link out,
https://www.tutorialspoint.com/cplusplus/cpp_conditional_operator.htm
I was thinking the homework was to describe each line of the code vs the overall program.
Topic archived. No new replies allowed.