If and Else If help


When the input is between 100 to 200 I want the output to be "steal", when the input is 1 or 0 I want the output to be "steal". And when the input is 0.5 I want the output to be "split".

I have the first two parts correct but cant seem to get the 0.5 part correct...please helpp

int main ()
int x;
cout << "Please enter an integer value: ";
cin >> x;

if ((x >= 100) && (x < 200)) // I will start the game with a steal.
{cout << "steal";}
else if (x == 0 ||x == 1 ) // if the result was 0, I will steal. if the result was 1, I will steal.
{cout << "steal";}
{cout << "split";} // if 0.5 = split


0.5 is a decimal value. C/C++ int's can't store anything other than whole numbers. You either need to change x to a float or double, or need to use a value other than .5.

Float works! thanks

I also need to create an exe file using this code where when I run


the program in my .exe file will read the input.

What do I have to do or add to my code to do this?

So if I run C:/project.exe(space)0.5, it should split "split".
Well, you have two options here. You can learn about file streams, which is the proper way to go, or you can alter stdin to accept from a file, which is the easy way to go. For example:

C:/dir/to/your/program/main.exe < C:/dir/to/your/file/input.txt
Topic archived. No new replies allowed.