I've been trying to solve this problem for days. I read the text, watched Buckyrooms C++ videos and other videos, unfortunately nothings sticking in my head... I know there has to be a counter, to print out 1., 2., 3., and then add 1 to the last integer but I cant type it out. So frustrating!
Any help would be great!
thx!
Write a program that asks the user to enter a positive integer and displays a table of numbers and
their factors, from 1 up to the number entered.
Below is a sample run:
Enter a positive integer: 8
1: 1
2: 1 2
3: 1 3
4: 1 2 4
Thank you for this!! quick question how does "void printFactor(int a)" and "printFactor(i)" translate to c++?
This is what I came up with, my factoring is wrong. I am pretty sure I am setting it up wrong.
[code]
int main()
{
int n,a; // declaration ok
cout<<"Enter the number: "; // output ok
cin>>n; // user input
for(int i = 1; i <= n; i++) //increment operator, starting at 1, stops when equal or less than user input.
{
cout<<i<<": "; //prints the users input individually
{
int factor=0; // ?
for(int i = 1; i <= factor; i++) //increment operator, starts at 1, less than a then goes up.
if(a%i ==0) //modulus operation
cout<<i<<": "; //output of the labe.
cout<<a <<" "; //output of the factors
cout<<endl;
}
}
return 0;
}
[code]