Applying Data Types. Computer Programming

Alright so I'm in a computer programming class and I was given the following problem:

Write a problem that takes an integer value and multiplies each of the digits together. 4 digit numbers only.
IE; What number do you want to process? 2684
Starting number 2684
End result 384

I know how to start the begging of the program, but i dont understand how to have it to where you can type in all four digits and then it will multiply each number by the other.



Also, what are some ways to change the color scheme of the program? I know how it works using CMD, but in Visual C++ its totally different aha.

Thanks!
Pipe it into a stream, and then extract the digits one at a time. Then you can do whatever you want to it.
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.
8-29-13
system("Color57")
#incude <iostream>
using namespace std;

{
int num1, num2, num3, num4;

cout<<"Enter four random digits."
cin>>




okay so after this im not sure to make it multiply each number by itself, help!
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>
#include <cctype>

int main()
{
	bool invalid = false;
	int x;

	do
	{
		std::string input;

		std::cout << "Enter a four-digit non-negative number: ";
		std::cin >> input;

		size_t j = 0;

		invalid = input.size() != 4    || 
		          !isdigit( input[0] ) || 
		          ( x = std::stoi( input, &j ), j != 4 );
	} while ( invalid );

	int product = 1;

	do { product *= x % 10; } while ( x /= 10 );

	std::cout << "Product of digits of the number is equal to " << product << std::endl;
}
What The ferror

Not supposed to just post an answer to questions that are homework related.
Topic archived. No new replies allowed.