Hey lieber programmierer, habe versucht ein ratespiel versucht in c++ zu schreiben, scheitere aber daran das die zufallszahl 44 ist, ich die zahl 5 eingegeben hab und trozdem "Richtig!!" erscheind. Hier mal mein source:
Code:
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int main(void){
int zahl;
int wert = 0;
int runden;
int zufallszahl;
int max = 100;
cout<<"Wie oft willst du spielen?:\n";
cin>>runden;
srand((unsigned int )time(NULL));
zufallszahl = rand() % 100 + 1;
while(wert<runden){
cout<<"Geb eine Zahl ein:\n";
cin>>zahl;
wert++;
if(zahl=zufallszahl){
cout<<"Richtig!!\n";
}
else{
cout<<"Falsch!!\n";
}
cout<<zufallszahl<<"\n";
}
system("pause");
return 0;
}