Tilfældigt tal (Gætte program)
Har programmeret et lille gætte program med føglende kode:// Copyright @ 2004 by RexOn - All rights reserved
// This application is licensed under the GPL open-source license
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int forsoeg = 3;
int tal;
int gaet;
int main()
{
tal = rand()%10;
while (forsoeg > 0 ) {
system ("CLS");
cout << "Du har " << forsoeg << " forsoeg tilbage! " << endl << endl;
cout << "Gaet et tal mellem 0 - 10" << endl;
cin >> gaet;
if ( gaet == tal )
{
cout << "Flot! Du gaettede rigtigt! " << endl;
system ("PAUSE");
return 0;
}
else if ( gaet < tal)
{
cout << "Dit gaet er for lavt! " << endl;
system ("PAUSE");
}
else // tallet maa vare fore hoejt
{
cout << "Dit gaet er for hoejt! " << endl;
system ("PAUSE");
}
forsoeg = forsoeg -1;
}
if (forsoeg = forsoeg -1)
{
system ("CLS");
cout << "Du har desvaerre ikke flere forsoeg tilbage.. :(!" << endl;
system ("PAUSE");
return 0;
}
system ("PAUSE");
return 0;
}
...........................................................
Programmet virker fint men tallet er altid nummer 1 .. har i evt. forslag til hvordan man får den til at vælge et tilfældigt tal...??