|
-
Jan 31st, 2001, 09:39 PM
#1
Thread Starter
Fanatic Member
I was wondering if anyone can help, because i cn get it to work in java but not in C++.
#include <iostream.h>
void main()
{
int input;
cout<<"Type in a number\n";
cin>>input;
for (int i = 1; i <= input; i++)
{
input = i * input;
}
cout<<input
}
like i said, i got it to work injava, but whenever i type something in here i get something totally different (like -1899959296 for 5 when it should be 120).
-
Feb 1st, 2001, 02:08 AM
#2
Frenzied Member
try it with this line instead:
cout << "Type in a number" << endl;
Harry.
"From one thing, know ten thousand things."
-
Feb 1st, 2001, 06:57 PM
#3
Thread Starter
Fanatic Member
Heh, I should have guessed. Lots of times whe ni have something like this i can use endl; and fix it. It's like the solution to all the world's problems or something....
-
Feb 1st, 2001, 07:02 PM
#4
New Member
No cheating Pete, figure it out for yourself. No using Math.PI. You have to learn the functions
-
Feb 1st, 2001, 07:36 PM
#5
Thread Starter
Fanatic Member
Hmm...it's still not working.
-
Feb 1st, 2001, 07:42 PM
#6
PowerPoster
try putting endl after all the lines
-
Feb 2nd, 2001, 05:08 AM
#7
Frenzied Member
It's because of the way you're using the input variable as a control variable for the loop. You can do it the way you're doing it with an extra variable, like this:
Code:
#include <iostream.h>
void main()
{
int input;
int output = 1;
cout<<"Type in a number" << endl;
cin>>input;
for (int i = 1; i <= input; i++)
output *= i;
cout<< output<< endl;
}
Harry.
"From one thing, know ten thousand things."
-
Feb 3rd, 2001, 02:50 PM
#8
Thread Starter
Fanatic Member
Cool, it works now. Thanks a lot for your help
Alcohol & calculus don't mix.
Never drink & derive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|