Hi all! I would like to show you my script because there something strange about the "bool Ripetere() " function.
The program seems to ignore the “std::getline” inside of that function, and if you try to type something, it will just close itself.
I’ve manage to do it the first time during the BullCowGame, but I can’t replicate it, and I don’t know why. Can someone help me? thank you very much!
#include <iostream>
#include <string>
int number;
int multiplier;
int InserisciNumero();
int MoltiplicaPer();
int Risultato();
bool Ripetere();
void main()
{
bool bRisposta = false;
do
{
InserisciNumero();
MoltiplicaPer();
Risultato();
bRisposta = Ripetere();
}
while (bRisposta);
std::cout << std::endl;
return;
}
int InserisciNumero()
{
std::cout << "Inserisci un numero intero: ";
std::cin >> number;
return 0;
}
int MoltiplicaPer()
{
std::cout << "Per quale valore intero vuoi moltiplicarlo? Inserisci un numero: ";
std::cin >> multiplier;
return 0;
}
int Risultato()
{
std::cout << number << " * " << multiplier << " = " << number * multiplier << std::endl;
std::cout << std::endl;
return 0;
}
bool Ripetere()
{
std::cout << "Vuoi fare un altro calcolo? (y/n)" << std::endl;
std::string Response = "";
std::getline(std::cin, Response);
return (Response[0] == 'y') || (Response[0] == 'Y');
}