• We've upgraded our forums. Please post any issues/requests in this thread.

String problem with c++ game

Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#1
Hi guys!
I am having a little problem with my latest game in c++
i know how to give an error if the user types in a wrong number,
but i dont know how to make it if the user types in a string!
Anyone can help?
This is the code of the error so far:
Code:
try
    {
        if (number < 1 || number > 9)
        {
            throw 1;
        }
    }
    catch(int x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#2
Tried this one:

Code:
try
    {
        if (number < z || number > a)
        {
            throw 1;
        }
    }
    catch(string x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#3
I think you can use something like this ...
Code:
if (static_cast<int>(number) == number)
{
    // it's an integer
}
else
{
    // it's not an integer
}
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#4
thanks :)
Where did you get that command btw?
It sounds very logic to me
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#5
I'm not sure what you are asking.
static_cast<> is a C++ operator.
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#6
Never mind. Seems i can't find the real solution of the problem.
Yours does the same thing as the one i wrote :p
Anyway, nice programming trick :)
(i was asking where is the site where you learnt it)

The real problem is that if i type a char or string instead of a number, the game never ends restarting
I have this problem with all my games and this is the only thing i have not learned yet!
(i mean, fixing this problem, my games, will not have a single "bug")
 

ctrain

New Member
Joined
Jan 12, 2010
Messages
393 (0.14/day)
Likes
72
#7
Never mind. Seems i can't find the real solution of the problem.
Yours does the same thing as the one i wrote :p
Anyway, nice programming trick :)
(i was asking where is the site where you learnt it)

The real problem is that if i type a char or string instead of a number, the game never ends restarting
I have this problem with all my games and this is the only thing i have not learned yet!
(i mean, fixing this problem, my games, will not have a single "bug")
cin is in the failure state and will just return immediately, you need to clear the fail state and wipe the input stream.

something like this:
Code:
int num;

std::cin >> num;
if(cin.fail())
{
	std::cout << "oh shit";
	
	std::cin.clear();							//clear the failure state
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); 	//clear the input stream
}

else
	...
 
Last edited:
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#8
What should i put in this row when i have numbers from 1 to 10 for example?
Code:
cin.ignore(numeric_limits<streamsize>max(), '\n');
 

de.das.dude

Pro Indian Modder
Joined
Jun 13, 2010
Messages
8,201 (2.99/day)
Likes
2,389
Location
Pune
System Name la de da... | Samsung NP355V5C-S05IN
Processor FX 8320 | AMD A8-4500
Motherboard ASRock 990FX Extreme 4 | Samsung something something
Cooling CM Hyper 212 EVO push:pull+ 1 panaflow 113CFM + 2 x 120mm NZXTs | Coolermaster Notepal
Memory 2x4GB DDR3 Corsair Vengeance 1600MHz CL9 | Samsunng 4GB + 2GB DDR3 1600MHz
Video Card(s) AMD 7790 GHZ edition! | 7670M + 7640G
Storage 1TB WD10EZEX | W.D 500GB Green AADS | Samsung 1TB
Display(s) dell S2240l 1080p IPS 21.5" | Samsung antiglare 15.6"
Case NZXT Guardian 921RB(@home) and Antec ASK4000B U3(Current)
Audio Device(s) Realtek ALC892 with THX True Studio | Realtek something
Power Supply Corsair GS600 | 90W Brick, 6 cell 48000mAh battery
Mouse Logitech G400, GOD TIER MOUSE!! LOGitech F310 gamepad!
Keyboard Logitech K200
Software Windows 8.1 x64 | Windows 8.1 x64
Benchmark Scores real men do bench presses not bench marks.
#9
have you tried using the isdigit() function?
header is ctype.h
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#10
Same problem with the isdigit() lol
All things i have tried, all worked the same :p
 

de.das.dude

Pro Indian Modder
Joined
Jun 13, 2010
Messages
8,201 (2.99/day)
Likes
2,389
Location
Pune
System Name la de da... | Samsung NP355V5C-S05IN
Processor FX 8320 | AMD A8-4500
Motherboard ASRock 990FX Extreme 4 | Samsung something something
Cooling CM Hyper 212 EVO push:pull+ 1 panaflow 113CFM + 2 x 120mm NZXTs | Coolermaster Notepal
Memory 2x4GB DDR3 Corsair Vengeance 1600MHz CL9 | Samsunng 4GB + 2GB DDR3 1600MHz
Video Card(s) AMD 7790 GHZ edition! | 7670M + 7640G
Storage 1TB WD10EZEX | W.D 500GB Green AADS | Samsung 1TB
Display(s) dell S2240l 1080p IPS 21.5" | Samsung antiglare 15.6"
Case NZXT Guardian 921RB(@home) and Antec ASK4000B U3(Current)
Audio Device(s) Realtek ALC892 with THX True Studio | Realtek something
Power Supply Corsair GS600 | 90W Brick, 6 cell 48000mAh battery
Mouse Logitech G400, GOD TIER MOUSE!! LOGitech F310 gamepad!
Keyboard Logitech K200
Software Windows 8.1 x64 | Windows 8.1 x64
Benchmark Scores real men do bench presses not bench marks.
#11
LOL something is borked i guess. things like this happen.
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#12
Are you calling the game() method on a bad input?
That's what restarting the game, no?

If not, I'm confused.

Are you trying to do something like this?

Code:
While input does not equal the exit command
{
  Get input
  if (input is valid)
  {
      Do something with valid input and ask for next input
  }
  else
  {
      If (input does not equal the exit command)
      {
          Throw an error an error and ask for a valid input
      }
   }
}
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#13
The problem is:
If the user types in a wrong integer like 3980218408....
that throws an error and the game goes back
If the user types in a string or char, that makes the game
restart infinitely
See the throw i have programmed in the first post

Also, your prototype is wrong as i don't mean to exit the game
The player could be anywhere, but if he doesn't press an integer
he looses the game and has to restart!
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#14
The pseudocode that I wrote would ask a player for input.
If the input was correct (valid) it would do something and then ask for the next input.
If the input was invalid, it would inform the player and then ask for input again.
If the player entered the "exit" string (whatever that may be) the game would quit.

Can you post your whole input code routine?
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#15
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <string>
#include <ctype.h>

using namespace std;

int main()
{
    game();
}

int game()
{
    cin >> number;

    try
    {
        if (number < 1 || number > 7)
        {
            throw 1;
        }
    }
    catch(int x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }
This is all needed, cuz the whole programming is 600 lines
I don't really think you will find anything with the code anyway.
 
Last edited:
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#16
Have you tried recursion*?

*Calling method x within method x.
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#17
You mean like this?
Code:
catch(int x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }
It is "recursioned", i just deleted like 70 lines of code in the post
If i put a string or char, the recursion continues infinitely (or a double || float)
 
Last edited:

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#18
You don't want recursion in this case as you are just filling the stack and heap for no good reason. You should not call the game() method from within itself just for bad input.
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#19
If i don't put the recursion, the game ends!
 

temp02

New Member
Joined
Mar 18, 2009
Messages
493 (0.15/day)
Likes
165
#20
You really shouldn't call the game function again when some error occurs, you would be increasing the call stack for no valid/good reason, use Kreij's approach and loop the game function call on main.
Also add "cin.clear();" to the catch, like so:
Code:
catch(int x)
{
  cout << "\n You typed a wrong number! ERROR: " << x << endl;
  cin.clear(); // flush the input error buffer
}
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#21
How about having x be a string (instead of an int) then try to parse it into an int? If it doesn't parse it should go to the catch.

EDIT: by x I mean the number you're inputting.
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.49/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#22
If you "cin" to an integer, it will automatically go into a fail state (can't convert) as ctrain pointed out. You can use this to check to see if the inputted value is a string as opposed to an integer.

If the inputted integer is out of range, a simple range check will do.
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#23
LOL
tried razaron's suggestion it works but ends in an unusual way!
I created 2 try functions, one with int x and one with char x
 
Joined
Apr 26, 2008
Messages
1,106 (0.31/day)
Likes
178
Location
london
System Name Staggered
Processor Intel i5 6600k (XSPC Rasa)
Motherboard Gigabyte Z170 Gaming K3
Cooling RX360 (3*Scythe GT1850) + RX240 (2*Scythe GT1850) + Laing D5 Vario (with EK X-Top V2)
Memory 2*8gb Team Group Dark @3000Mhz 16-16-16-36 1.25v
Video Card(s) Inno3D GTX 1070 HerculeZ
Storage 256gb Samsung 830 + 2*1tB Samsung F3 + 2*2tB Samsung F4EG
Display(s) Flatron W3000H 2560*1600
Case Cooler Master ATCS 840 + 1*120 GT1850 (exhaust) + 1*230 Spectre Pro + Lamptron FC2 (fan controller)
Power Supply Enermax Revolution 85+ 1250W
Software Windows 10 Pro 64bit
#24
Why and what 2 try functions?
 
Joined
Dec 2, 2009
Messages
3,257 (1.11/day)
Likes
315
System Name Mercury KM-81
Processor Phenom II x4 B50
Motherboard ASUS M4A89GTD PRO
Cooling Cooler Master Hyper TX3
Memory 6GB Ram (4GBx1 Corsair 2GBx1 Nanya)
Video Card(s) PowerColor AX6770 V2.0
Storage 2TB WD Black, 1TB Hitachi, 500 GB WD Blue
Display(s) Philips 247E-LPH 24" 1920x1080
Case Mercury
Audio Device(s) Integrated Realtek
Power Supply Corsair 750TX
Software Windows 7 64-bit
Benchmark Scores Maybe it is time to benchmark :D
#25
Code:
try
    {
        if (number < 1 || number > 7)
        {
            throw 1;
        }
    }
    catch(int x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }
try
    {
        if (number < 1 || number > 7)
        {
            throw 2;
        }
    }
    catch(char x)
    {
        cout << "\n You typed a wrong number! ERROR: " << x << endl;
        game();
    }