I need help with that if statement. Tt works the first time when there's a perfect square or a double-digit number, but after the first time it keeps doing it for the other numbers too, is there a way to make this not happen?
Thank you
#include<iostream>
#include<time.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int dice()
{
return rand()%6+1;
}
string check(int tempspot, string &message)
{
if(tempspot == 11 || tempspot == 22 || tempspot == 33 || tempspot == 44 || tempspot == 55 || tempspot == 66 || tempspot == 77 || tempspot == 88 || tempspot == 99) {
message = "go to jail";
return message;
}
if(sqrt(tempspot) * sqrt(tempspot) == tempspot) {
message = "perfect square";
return message;
}
else
return "";
}
int main()
{
int sum=0;
string message;
srand(time(NULL));
cout.precision(ios::right);
cout<<"Rolls ";
cout.precision(ios::left);
cout.width(10);
cout<<"Temp-Spot";
cout.precision(ios::right);
cout.width(10);
cout<<"Prize";
cout.width(10);
cout<<"Message";
do {
cout<<"\n"<<dice();
cout.precision(ios::left);
sum +=dice();
cout.width(10);
cout<<sum<<"\n";
cout.width(25);
check(sum, message);
if(message == "perfect square") {
cout<<"+10";
sum += 10;
}
else if(message == "go to jail") {
cout<<"10";
sum = 10;
}
cout.width(20);
cout<<message;
}while(sum<=100);
return 0;
}