MegaGlest Forum
Off topic => Off topic => Topic started by: Gabbe on 11 October 2010, 17:34:21
-
#include <iostream>
#include <cmath>
#include <cstdlib>
int main(){
using namespace std;
double y;
y = rand();
cout << y << endl;
cin.get();
return 0;
}
code in c++, sumposed to generate a random number, but it won`t :S
BTW system("pause"); replaced with cin.get(); doesnt work either :(
-
You need to initialize the pseudo-random generator with srand, mostly srand(time(NULL)).
See:
http://cplusplus.com/reference/clibrary/cstdlib/rand/
-
I think i might have goten a C::B related problem, I tried to run a new program that were supposed to do 5 * 5 * 5.
#include <iostream>
#include <cmath>
#include <cstdlib>
int main(){
using namespace std;
double rainbow;
rainbow = pow(5,3);
cout << rainbow << endl;
cin.get();
return 0;
}
No output when it tried to build, but the error log said:
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
-------------- Build: Release in begining functions ---------------
Compiling: main.cpp
mingw32-g++.exe: installation problem, cannot exec `cc1plus': No such file or directory
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
-
Basically, you have to seed the random numbers. Otherwise its the same "random" number every time. Yggrdasil's link might help.
-
Not anything i write in C::B works any :(
-
C::B is code blocks, right? Code doesn't depend on the compiler really. You're simply doing it wrong.
-
Build&run?
Yeah, "Code::Blocks"(http://2.bp.blogspot.com/_O-rOxpu66eY/R9P3jgzqW7I/AAAAAAAAABw/6TYnyo8YAFw/s320/Code_Blocks_logo.jpg)
Dev c++ works..