Applying Data Types Help

Hello, I'm trying to finish a project that has a 4-digit number multiply each digit together in order to receive a product number. Here is what I have:

#include <iostream>
using namespace std;

int main()

{
int whole_num;

int digit1, digit2, digit3, digit4; //digits = the 4 digits in the whole_num

int num1, num2, num3; //nums = the nums outputted in order to get the digits

int product_num; //The product number that has each digit mulitplied

cout<< "Hello, please enter a 4-digit whole number. \n";
cin>> whole_num;

digit1 = whole_num/1000;
num1= digit1%1000;

digit2= num1/100;
num2= digit2%100;

digit3= num2/10;
num3= digit3%10;

digit4= num3/1;

product_num= digit1*digit2*digit3*digit4;

cout<< "The product of all the digits multiplied together is.. \n" << product_num << endl;
//Shows the user what the product of each digit is when multiplied together

system ("pause");

return 0;

}


It runs, but the product is always 0. What did I do wrong?
If at least one digit is equal to 0 then the product also will be equal to 0.
How exactly would I change that from happening? I tried entering a lot of high and low numbers and the results are the same
Your are not the first with that assignment recently. I wonder if you are on the same course.

num1 is less than 10, so digit2 and the rest are always 0.

http://www.cplusplus.com/forum/beginner/1/ says something about "homework", but that aside http://www.cplusplus.com/forum/beginner/109520/ shows a different idea.
You have a typo

Instead of

digit1 = whole_num/1000;
num1= digit1%1000;

digit2= num1/100;
num2= digit2%100;

digit3= num2/10;
num3= digit3%10;

write

digit1 = whole_num/1000;
num1= whole_num%1000;

digit2= num1/100;
num2= num1%100;

digit3= num2/10;
num3= num2%10;
Actually I think my buddy posted something about this too.

So with the second link would n=whole_num and g=product_num for me?
(I'm new to this and still learning about codes)
Thanks Vlad! It finally works :3
Topic archived. No new replies allowed.