So i want to have a code that returns a random number between 5 and 12 and i want to have a difrent number every run.
Printable View
So i want to have a code that returns a random number between 5 and 12 and i want to have a difrent number every run.
Yea i allready tryed that...
I tryed the one under:
And i got this:Quote:
It's best to encapsulate this process in a function so that it can be called as many times as required.
Quote:
------ Build started: Project: Joost2, Configuration: Debug Win32 ------
Compiling...
Item1.cpp
c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(31) : error C3861: 'time': identifier not found
Build log was saved at "file://c:\Documents and Settings\Joost van Doorn\Mijn documenten\Visual Studio 2005\Projects\Joost2\Joost2\Debug\BuildLog.htm"
Joost2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
That error means you forgot to include ctime header file.Quote:
: error C3861: 'time': identifier not found
Code:#include <ctime>
...
... // other stuff here
>error C3861: 'time': identifier not found
That program had a bug in that it didn't include time.h. That usually ends up working in C, but fails miserably in C++ because C++ requires a prototype.
Genereer gewoon een random nummer en doe daar jouwn mimimun waarde bij, oftewel + 5. Om te zorgen dat je programma niet 2 keer dezelfde waarde genereerd moet je de waarde die je programma genereerd in bijvoorbeeld een integer zetten, kijk dan of je nieuwe gegenereerde nummer gelijk is aan een eerder gegenereerd nummer, zo ja genereer nog een keer tot dat het nieuwe gegenereede nummer niet gelijk is, als je hulp nodig hebt post ik mijn code wel even waarin dat gebeurd maar je kan het beter zelf doen want dan leer je er nog van, succes.
Thank you for your help. I got a warning but it's working now ;)
How you know i'm dutch.
Your name is very dutch, :P. Also "\mijn documenten". Anyway I will post a little program I made one day which uses the random funcion but will not use it twice:
PHP Code:
#include <iostream>
#include <windows.h>
using namespace std;
string S [ 256 ] [ 256 ],
S2 [ 256 ] [ 256 ],
C;
int i,
j,
k,
l [ 256 ] [ 256 ],
m [ 256 ] [ 256 ],
n [ 256 ] [ 256 ],
o,
p [ 256 ] [ 256 ],
NO [ 256 ] [ 256 ];
int main()
{
cout<< "How many words?: ";
cin>> C;
if ( isdigit ( C [ 0 ] ) &&
isdigit ( C [ 1 ] ) || C [ 1 ] == '\0' &&
isdigit ( C [ 2 ] ) || C [ 2 ] == '\0' )
{
i = atoi ( C.c_str() );
if ( i < 1 || i > 100 )
{
system ( "cls" );
cout<< "Wrong Input!";
cin.ignore();
cin.get();
exit ( 0 );
}
}
else
{
system ( "cls" );
cout<< "Wrong Input!";
cin.ignore();
cin.get();
exit ( 0 );
}
system ( "cls" );
NO [ '\0' ] [ 1 ] = 2;
i++;
for ( j = 1; j < i; j++ )
{
cout<< "Enter here the NL word: ";
cin>> S [ j ] [ '\0' ];
cout<< endl;
cout<< "Enter here the OL word: ";
cin>> S [ '\0' ] [ j ];
cout<< endl;
}
i--;
system ( "cls" );
for ( l [ 1 ] [ '\0' ] = 0, l [ '\0' ] [ 1 ] = 0, n [ 1 ] [ '\0' ] = 0, n [ '\0' ] [ 1 ] = 0, p [ 1 ] [ '\0' ] = 0, p [ '\0' ] [ 1 ] = 0; ( l [ 1 ] [ '\0' ] + l [ '\0' ] [ 1 ] ) < ( i * 2 ); )
{
srand ( ( unsigned ) time ( 0 ) );
if ( NO [ '\0' ] [ 1 ] == 0 )
{
NO [ 1 ] [ '\0' ] = 0;
}
else if ( NO [ '\0' ] [ 1 ] == 1 )
{
NO [ 1 ] [ '\0' ] = 1;
}
else if ( NO [ '\0' ] [ 1 ] == 2 )
{
NO [ 1 ] [ '\0' ] = rand() % 2;
}
if ( NO [ 1 ] [ '\0' ] == 1 )
{
k = '\0';
j = rand() % i + 1;
for ( o = 1; o < i; o++ )
{
if ( m [ o ] [ '\0' ] == j )
{
o = 0;
j = rand() % i + 1;
}
}
n [ 1 ] [ '\0' ]++;
m [ n [ 1 ] [ '\0' ] ] [ '\0' ] = j;
l [ 1 ] [ '\0' ]++;
if ( l [ 1 ] [ '\0' ] >= i )
{
NO [ '\0' ] [ 1 ] = 0;
}
}
if ( NO [ 1 ] [ '\0' ] == 0 )
{
j = '\0';
k = rand() % i + 1;
for ( o = 1; o < i; o++ )
{
if ( m [ '\0' ] [ o ] == k )
{
o = 0;
k = rand() % i + 1;
}
}
n [ '\0' ] [ 1 ]++;
m [ '\0' ] [ n [ '\0' ] [ 1 ] ] = k;
l [ '\0' ] [ 1 ]++;
if ( l [ '\0' ] [ 1 ] >= i )
{
NO [ '\0' ] [ 1 ] = 1;
}
}
cout<< S [ j ] [ k ]<< " means: ";
cin>> S2 [ k ] [ j ];
cout<< endl;
if ( S2 [ k ] [ j ] == S [ k ] [ j ] )
{
cout<< "Correct!";
Sleep ( 1000 );
p[ 1 ] [ '\0' ]++;
}
else
{
cout<< "Wrong!";
Sleep ( 1000 );
p [ '\0' ] [ 1 ]++;
}
system ( "cls" );
}
cout<< "Done!"<< endl<< endl;
cout<< "You had "<< p [ 1 ] [ '\0' ]<< " correct awnsers and "<< p [ '\0' ] [ 1 ]<< " wrong awnsers."<< endl<< endl;
cout<< "Your score would be "<< ( ( p [ 1 ] [ '\0' ] * 100 ) / ( i * 2 ) )<< "% out of 100%";
cin.ignore();
cin.get();
}