When I Enter Trig or Pythag The Ifs Statements Will Not Work And Then This Will Be Printed "Pythagorasry" Even Though I Have Not Typed That. I Believe This Is Trigonometry And Pythagoras Conflicts But Im Not Sure. Also The If Statements Wont Work I Can Enter Anything And It Will Print The Text. Someone Help.
Also Explain Your Code Due To Me Being A Beginner
I Left In The PlaceCursor Statement To See Where I Was Getting PlaceCursor()From.
void PlaceCursor(constint x, constint y){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD PlaceCursorHere;
PlaceCursorHere.X = x;
PlaceCursorHere.Y = y;
SetConsoleCursorPosition(hConsole, PlaceCursorHere);
return;
}
int main()
{
//PlaceCursor(65,0); Is Perfect For List
PlaceCursor(25,0); printf("Welcome To The Maths Test Helper");
cout<<"\n\nWelcome To ";
cout<<Name;
cout<<"Here We Will Help You With Your Maths Revision. ";
cout<<"\nYou Will Start Off By Entering By How Many Things You Want To Revise Then You\n";
cout<<"Will Enter What You Want You Want To Revise And You Will Be Given A Random\nQuestions Based On Your Selected Topics.\n\n";
PlaceCursor(25,5); printf("What Topics Do You Want To Revise?\nTopic:");
string Topic1;
cin>>Topic1;
if (Topic1 == "Trigonometry" || "Trig" || "trigonometry" || "trig"){
PlaceCursor(65, 7); printf("Trigonometry");
}if (Topic1 == "Pythagoras" || "Pythag" || "pythagoras" || "pythag"){
PlaceCursor(65, 7); printf("Pythagoras");
}else {
cout<<"Wrong";
}
Firstly, starting every word with a capital letter like that makes your post harder to read. The harder your post is to read, the fewer people will make the effort to read it, which means the fewer people will help you.
Looking at your code:
if (Topic1 == "Trigonometry" || "Trig" || "trigonometry" || "trig")
That's not how you combine multiple conditions. What that does is the following:
If Topic1 == "Trigonometry" is true, OR
if "Trig" is true, OR
if "trigonometry" is true, OR
if "trig" is true.
Since "Trig", "trigonometry" and "trig" are all strings, they are all non-zero char pointers. Being non-zero, they all evaluate to true. So your condition is always true. Your program will always execute the first block, writing the word "Trigonometry", and then will always execute the second block, writing the word "Pythagoras" at the same location. So your final result is the word "Pythagoras" followed by the last two letters of "Trigonometry", which didn't get overwritten.
Once you fix the conditions in your if statements, it should all work fine.