Skrót tego o co mi chodzi
liczba losowa + liczba losowa = absurdalny wynik (niektóre ujemne)
Szukałem w czym może być problem, ale nie wiem. Domyślam się jedynie, że podczas generowania liczby losowej jakiś błąd się wkrada, jednak wynik losowej liczby wyświetlany jest prawidłowo
#include "stdafx.h"
#include "iostream"
#include "string"
#include "cstdlib"
#include "time.h"
using namespace std;
int los(int nLos1, int nLos2)
{
srand((unsigned int)time(NULL));
nLos1 = rand() % 10 + 1;
nLos2 = rand() % 10 + 1;
cout << "Ile to jest " << nLos1 << " + " << nLos2 << " = ";
return (nLos1, nLos2);
}
int _tmain(int argc, _TCHAR* argv[], int nLos1, int nLos2)
{
int iWyn, iWyn2;
los(nLos1, nLos2);
cout << nLos1 + nLos2;
cin >> iWyn;
if (iWyn == nLos1 + nLos2)
{
cout << "Dobrze!" << endl;
}
else
cout << "zle " << endl;
system("pause");
}
cout << nLos1 + nLos2;
ta linijka wyświetla błędny wynik, jest wstawiony tylko do sprawdzenia wyniku.
dodanie znacznika <code class="cpp">
- @furious programming