When I run this code, I get the following error Screenshot erore
50:7: error: no match for 'operator<<' (operand types are 'std::__ndk1::ostream' {aka 'std::__ndk1::basic_ostream'} and 'void') cout << generateRandomNumber(); compilation terminated due to -Wfatal-errors.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
// class game
class mathGames
{
public:
mathGames();
void generateRandomNumber();
void calculate();
void show();
void answer();
private:
int x;
int y;
int z;
char ans;
};
// constructor
mathGames::mathGames()
{
x = 0;
y = 0;
}
// generate random numbers
void mathGames::generateRandomNumber()
{
srand (time(NULL));
x = rand()%9+1;
y = rand()%9+1;
}
// calculate numbers
void mathGames::calculate()
{
z = x + y;
}
// show generate number
void mathGames::show()
{
cout << " " << x << " + "
<< y << " = " << z << endl;
}
// user answer
void mathGames::answer()
{
cout << " true or false (t/f) ? ";
cin >> ans;
if (ans == 't')
cout <<
generateRandomNumber();
}
// main
int main ()
{
mathGames number;
number.generateRandomNumber();
number.calculate();
number.show();
number.answer();
}
Aucun commentaire:
Enregistrer un commentaire