hello guys i have some errors and questions in my game...
1) The program dont want to close when the player will wrong the answer
1 2 3 4 5 6 7 8 9 10 11 12
int Answers()
{
if(ans == "13")
{
cout << "You are filled in your bank account $50" << endl;
money += 50;
}else{
cout << "[!] Wrong" << endl;
system("PAUSE");
returnfalse;
}
}
2) I want to know how to detect the words in the game like (a,b,c,d,e,f...)
when u will enter word to say "You need to enter number"
3) And also how do i make the program returns after ending ... :D
here is the whole script ...
1) Your function is supposed to return an int, but you return a boolean false. If you want to end the program then you will have to check the Answers() return value in main(), and return0 from main (like you would in any other function). Returning from main ends the program.
2) The easiest way to validate input:
1 2 3 4 5 6 7 8
int some_number;
std::cout << "Please enter a number: ";
std::cin >> some_number;
if (std::cin.fail() == true) //if the input could not be converted to a number
{
//...
}
3) I'm not sure what you mean by this question - but I assume you mean how to keep repeating the process:
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <winable.h>
#include <limits>
#include <ctime>
usingnamespace std;
int money = 10,num,dice;
string ans;
int Answers()
{
if(ans == "13")
{
cout << "You are filled in your bank account $50" << endl;
money += 50;
}
if(ans != "13")
{
cout << "[!] Wrong" << endl;
system("pause");
}
}
int Questions()
{
cout << "If you answer true u will filled in bank $50" << endl;
cout << "How much is 7 + 6 ?" << endl;
getline(cin, ans);
Answers();
}
int main()
{
char roll;
{
while (true)
{
cout<< "Money in bank: $" << money << endl;
cout<< "Please enter your guess for the next roll. It only costs $1.00 to play, If you are correct I will pay you $100" <<endl;
cin >> num;
cin.get(roll);
srand(time(NULL));
dice = (rand()%6)+1;
int some_number;
std::cin >> some_number;
if (std::cin.fail() == true)
{
BlockInput(true);
cout << "[!] Please enter a number." << endl;
system("pause");
returnfalse;
}
if(num > 6 || num < 1)
{
system("cls");
cout << "[!] You can't enter hieger number of 6 or lower than 1" << endl;
cout << "Try again !" << endl;
system("PAUSE");
returnfalse;
}
if(money <= 0)
{
cout << "You dont have money!" << endl;
cout << "You can enter moeny in bank if you answer on some questons." << endl;
Questions();
}
if (num == dice)
{
cout << "Rolling the dices..." << endl;
Sleep(2500);
system("cls");
cout << "Your number " << num << endl;
cout << "Winner! The dice rolled " << dice <<endl;
money += 100;
cout << "Your bank account is now $" << money << endl;
cout << "\n";
}
elseif (num != dice)
{
cout << "Rolling the dices..." << endl;
Sleep(2500);
system("cls");
cout << "Your number " << num << endl;
cout << "Sorry the dice rolled " << dice <<endl;
money -= 1;
cout << "Your bank account is now $" << money << endl;
cout << "\n";
}
}
}
return 0;
}
When ill start the program runs good but when ill tupe number i need to tupe another number to start the rolling...
and i also dont get it where to put that "int Answers()" when the answer is not correct.
And also tell me where need to be this code
1 2 3 4 5 6 7 8 9
int some_number;
std::cin >> some_number;
if (std::cin.fail() == true)
{
BlockInput(true);
cout << "[!] Please enter a number." << endl;
system("pause");
returnfalse;
}
Thanks :)
Please try it your self to see what is the problem im not good at english much .... :/