I have recently been working on a game where two players battle by guessing a number. But with not a lot of succes. In my first testrun I choose easy mode but the number was higher than 100 (ended up around 8912). The wierd part is that when the number given by the player was higher than 8192 it outputed both
number is higher
and
number is lower
Is there somthing wrong with this function? Or might it be my main function?
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <string.h>
#include <fstream>
usingnamespace std;
struct RecAbbo{
std::string name;
std::string surname;
int games;
int won;
int same;
int lost;
int money;
}Abbo[100];
void play(int pl1, int pl2);
int main(){
char name1[20],name2[20],surname1[20],surname2[20];
int i1, i2, i = 0;
bool check = false, check2 = false ;
while (check == false){
i1 = rand() % 100;
i2 = rand() % 100;
while (check2 == false)
if (i1 == i2){
i2 = (i2 + rand() % 100) - 100;
} else {
if (Abbo[i1].name.empty() == 0 || Abbo[i2].name.empty() == 0){
check2 = false;
} else {
check2 = true;
check = true;
}
}
}
while (i < 20){
name1[i] = Abbo[i1].name[i];
name2[i] = Abbo[i2].name[i];
surname1[i] = Abbo[i1].surname[i];
surname2[i] = Abbo[i2].surname[i];
i++;
}
Abbo[i1].games++;
Abbo[i2].games++;
cout<<" player 1: player 2: \n";
cout<<"game: "<<name1<<surname1<<" VS :"<<name2<<surname2<<endl;
play(i1,i2);
}
This is part of a bigger program. I just created a new file to reproduce the error. There are also a few errors in that file but that is for an other toppic