#include <iostream>
usingnamespace std;
int main()
{
cout<<"Please Choose A Number Between 1 And 8 In Your Mind"int a,b,c,d;
char e,f,j;
Cout<<"Is Your Number Odd Or Even (O/E)?";
Cin>>e;
if (a=="E" || a=="e")
cout<<"Is Your Number Lower Or Higher Than 4 (L/H)?"
Cin>>f;
if (f=="l" || f=="L")
cout<<"Is Your Number Lower Or Higher Than 3 (L/H)?"
Cin>>j;
if (j=="l" || f=="L")
cout<<"Your Number Is 2"elseif (j=="h" || f=="H")
cout<<"Your Number Is 4"else
cout<<"error";
elseif (f=="h" || f=="H")
cout<<"Is Your Number Lower Or Higher Than 7 (L/H)?"
Cin>>j;
My first advise will be: use comments! it's very helpfull, then you won't get so confused. Second i think you can divide your program into some functions. Third try using switch - case, it might help as well.. good luck!
Consider using round braces {} to group the if/else blocks of statements that are meant to belong together. Your code looks as if you are under the impression that indentation matters in c++. It doesn't, unlike that other language named after a type of snake starting with P. But braces do, as well as semicolons. The first cout statement you've written needs to be separated (using a semicolon) from the declarations of integer variables a,b,c and d that follow it. I'm guessing you mean to have semicolons after all the cout statements in there and braces around all the cout and cin statements on neighbouring lines.
Also capitalisation matters too, ie. whether your type names, variable names and keywords are in lower or upper case. So cout is a standard type name but Cout is not.
Also C++ has no built-in string comparison operator. So if you mean to check that the variable f has the character "L" in it you need to compare it to the character 'L' not a string "L". So for instance, line 13 should look like this: if (f=='l' || f=='L')
Thanks Man
I Have To Say This Is My First Time With C++
and This is my first Code
Now Here Is My New Problem
I Have To Use Binary Search To Write This Code
But I Don't Know How ??? Or What Binary Search Is For That Matter !!!
By The Way Can Anyone Compile The Code And See If There Is Any Problem With It ???? ( I Mean The Solution and Every Thing)
By The Way
How Can I Make The Program To Exit After It Guessed the Number ???
#include <iostream>
usingnamespace std;
int main()
{
char a,b,c;
cout<<"\nPlease Choose A Number Between 1 And 8 In Your Mind\n\n\n";
cout<<"Question No.1 : Is Your Number Odd Or Even (O/E)?\n\n";
cin>>a;
if (a=='E' || a=='e')
{
cout<<"Question No.2 : Is Your Number Lower Or Higher Than 5 (L/H)?\n\n";
cin>>b;
if (b=='l' || b=='L')
{
cout<<"Question No.3 : Is Your Number Lower Or Higher Than 3 (L/H)?\n\n";
cin>>c;
if (c=='l' || c=='L')
cout<<"Your Number Is 2\n";
elseif (c=='h' || c=='H')
cout<<"Your Number Is 4\n";
else
cout<<"Error\n";
}
elseif (b=='h' || b=='H')
{
cout<<"Question No.3 : Is Your Number Lower Or Higher Than 7 (L/H)?\n\n";
cin>>c;
if (c=='l' || c=='L')
cout<<"Your Number Is 6\n";
elseif (c=='h' || c=='H')
cout<<"Your Number Is 8\n";
else
cout<<"Error\n";
}
else
cout<<"Error\n";
}
elseif (a=='o' || a=='O')
cout<<"Question No.2 : Is Your Number Lower Or Higher Than 4 (L/H)?\n\n";
cin>>b;
if (b=='l' || b=='L')
{
cout<<"Question No.3 : Is Your Number Lower Or Higher Than 2 (L/H)?\n\n";
cin>>c;
if (c=='l' || c=='L')
cout<<"Your Number Is 1\n";
elseif (c=='h' || c=='H')
cout<<"Your Number Is 3\n";
else
cout<<"Error\n";
}
elseif (b=='h' || b=='H')
{
cout<<"Question No.3 : Is Your Number Lower Or Higher Than 6 (L/H)?\n\n";
cin>>c;
if (c=='l' || c=='L')
cout<<"Your Number Is 5\n";
elseif (c=='h' || c=='H')
cout<<"Your Number Is 7\n";
else
cout<<"Error\n";
}
return 0 ;
}