Simple C++ question

I'm sort of new C++. Last night, I thought of something. I want to multiply a 3-digit number. For example, 441 would be equal to 16 (4 * 4 * 1). How would I go about doing this? This is what I tried, I know it's wrong. If anyone can shed some light on this topic for me, I would appreciate it :). Thanks for reading.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

#include <iostream>
using namespace std;

  int main() {
  int num;

  cout << "Enter a 3-digit number: ";
  cin >> num;

  cout << "The product of " << num << " is " << num * num * num;
  
  return 0;
}
The program isn't gonna know that you want each digit multiplied by the other digits. Anything you take for granted in your brain is gonna have to be hard coded into the compiler.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

int main( void)
{
    int hundredsDigit;
    int tensDigit;
    int onesDigit;
    int number;

    cout << "Enter a 3 digit number: ";
    cin >> number;

    hundredsDigit = number / 100;
    tensDigit = (number/10) % 10;
    onesDigit = number % 10;

    cout << "The product of " << number << " is " << hundredsDigit*tensDigit*onesDigit;

    return 0;
}
Last edited on
Topic archived. No new replies allowed.