I am having an issue with my program. The object is for two coins to be flipped simultaneously and to have the user guess beforehand whether the coins will be equal (even) or if the will be different (odd). I have tried several different ways of writing the code and am stuck. Before I tried to move the function getPrediction() out of the do while loop, the program would run twice and quit. Now that I have moved it out of the do while loop I keep getting a ::toss is not specified error. I am trying to get it where I do not alter the class file (coin.hpp) or the coin.cpp (implementation file). I am trying to figure out how to structure main so that this is possible. Thank you for any help you can give me. I appreciate it.
modelling heads and tails as two numbers 1 and 2, the following program captures correct and incorrect guesses for two coins showing heads and tails simultaneously:
#include <iostream>
#include <random>
#include <chrono>
int main()
{
bool fQuit = false;
int correctChoice{}, wrongChoice{}, runs{};
while (!fQuit)
{
std::cout << "Select 1 to guess, 2 to quit \n";
int choice{};
std::cin >> choice;//do input validation here
switch(choice)
{
case 1:
{
std::cout << "Select 1 for both coins same, 2 for different \n";
int choice{};
std::cin >> choice;//do input validation here
auto seed = std::chrono::system_clock::now().time_since_epoch().count();//seed
std::default_random_engine dre(seed);//engine
std::uniform_int_distribution<int> di(1, 2);//distribution
auto a = di(dre); auto b = di(dre);//generates numbers 1 and 2 randomly
if (((choice == 1) && (a == b)) || ((choice == 2) && (a != b)))
//correct guess: when user choooses same && both coins are same ...
//... or when user chooses different && both coins are not same
{
std::cout << "Correct guess \n";
++correctChoice;
}
else
{
std::cout << "Wrong guess \n";
++wrongChoice;
}
++runs;
}
break;
case 2:
std::cout << "You played " << runs << " times \n";
std::cout << "Correct choices " << correctChoice;
std::cout << "\nWrong choices " << wrongChoice;
std::cout << "Goodbye"
fQuit = true;
break;
default:
std::cout << "Wrong choice, try again \n";
break;
}
}
}