TEACH ME! IT'S YOUR JOB!
Wait.....
Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo
Anonymous wrote:merlinfire wrote:I never really got any useful comments except splitting hairs
TEACH ME! IT'S YOUR JOB!
Wait.....
I do not get it?
merlinfire wrote:I meant comments about my solution to this problem.
merlinfire wrote:I meant comments about my solution to this problem.
if ((y==x-1 || y==x) && prime !=1)
{
cout << " " << x << endl;
prime=1;
// <-- missing statement here.
} #include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int oneleft=0;
int x=0;
int y=0;
cout << "Factorial Prog 1.01." << endl;
cout << "Enter your number to be decomposed for factors." << endl;
cin >> x;
cout << endl;
int prime=0;
int factorfest=0;
while (prime==0)
{
factorfest=0;
y=1;
while (factorfest==0)
{
if (x==0 || x==1)
{
cout << "Your number is a " << x <<". It cannot be factored. What a ch00b."<< endl;
prime =1;
factorfest=1;
}
y++;
if (x%y==0 && prime!=1)
{
cout << y <<" x ";
x=x/y;
factorfest=1;
}
if ((y==x-1 || y==x) && prime !=1)
{
cout << " " << x << endl;
prime=1;
factorfest=1;
}
}
}
system("PAUSE");
return 0;
}tomcant wrote:merlinfire wrote:I'm not sure how to check whether the input is a number or not...
isdigit(num);
merlinfire wrote:tomcant wrote:merlinfire wrote:I'm not sure how to check whether the input is a number or not...
isdigit(num);
Thanks! Is there a particular library I must include for that function?
#include <iostream>
using namespace std;
int main()
{
cout << "Enter a number to factor: ";
int first = 2, val;
cin >> val;
cout << "Prime factors = ";
for(; val >= first*first; ++first)
{
for(; val % first == 0;)
{
cout << first;
if(val > first) cout << " x ";
val /= first;
}
}
if(val > 1) cout << val;
cin.ignore();
cin.get();
return(0);
}#include <iostream>
using namespace std;
int main()
{
cout << "Enter a number to factor: ";
int first = 2, val;
cin >> val;
if(val <= 3)
{
cout << "Prime factors = " << val << endl;
cin.ignore();
cin.get();
return(0);
}
cout << "Prime factors = ";
for(; val >= first*first; ++first)
{
for(; val % first == 0;)
{
cout << first;
if(val > first) cout << " x ";
val /= first;
}
}
if(val > 1) cout << val;
cin.ignore();
cin.get();
return(0);
}tomcant wrote:I think, since I'm the host, I am not supposed to? But if you wanna see my version, sure...
Please comment
Users browsing this forum: No registered users and 1 guest