### Simple If statement problem

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182`` ``````// Geometry Chapter 9 Project.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "iostream" #include "stdio.h" #include #include #include #include using namespace std; void QuestionOne () { cout << "Question 1:" << endl << endl; int q1x, q1y, q1vx, q1vy, q1ax, q1ay; q1x = rand() % 10 + 1; q1y = rand() % 10 + 1; q1vx = rand() % 10 + 1; q1vy = rand() % 10 + 1; cout << "Point " << q1x << ", " << q1y << " is being translated with vector <" << q1vx << ", " << q1vy << ">." << endl << "What are the coordinated of the new image formed?" << endl; cout << "x = "; cin >> q1ax; cout << endl << "y = "; cin >> q1ay; cout << endl; if (q1ax == (q1x + q1vx) && q1ay == ( q1y + q1vy)) { cout << "Correct! Next Question..." << endl << endl; QuestionTwo (); } else { cout << "Incorrect! Please try again" << endl << endl; QuestionOne (); } } void QuestionTwo () { int q2x, q2y, q2ax, q2ay; q2x = rand() % 10 + 1; q2y = rand() % 10 + 1; q2ax = q2y; q2ay = q2x; cout << "Point " << q2x << ", " << q2y << "is being rotated 90 degrees clockwise." << endl << "What are the coordinates after the rotation?" << endl << endl; cout << "x = "; cin >> q2ax; cout << endl << "y = "; cin >> q2ay; cout << endl; if (q2ax == q2y && q2ay == q2x) { cout << "Correct!" << endl << endl; } else { cout << "Incorrect! Try again..." << endl << endl; QuestionTwo(); } } int main() { srand(time(0)); cout << "Geometry Chapter 9" << endl << endl; QuestionOne (); system ("pause"); return 0; } ``````

I am not getting a "Correct!" or "Incorrect!" whether I get it right or wrong. What's the problem? Plus I am receiving build errors but I don't know from where.
Last edited on
A) remove all unneccesary includes, leave only
 ``12`` ``````#include #include ``````

B) Forward declare QuestionTwo():
 ``12345678910`` ``````void QuestionTwo(); //Forward declaration void QuestionOne() { //... } void QuestionTwo() //Definition { //... ``````

C) How do you know if you have some runtime error if your project doesn't compile?
To answer C when I build without compiling it says 0 succeeded 1 failed

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````// Geometry Chapter 9 Project.cpp : Defines the entry point for the console application. // #include "iostream" #include using namespace std; void QuestionTwo(); void QuestionOne () { cout << "Question 1:" << endl << endl; int q1x, q1y, q1vx, q1vy, q1ax, q1ay; q1x = rand() % 10 + 1; q1y = rand() % 10 + 1; q1vx = rand() % 10 + 1; q1vy = rand() % 10 + 1; cout << "Point " << q1x << ", " << q1y << " is being translated with vector <" << q1vx << ", " << q1vy << ">." << endl << "What are the coordinated of the new image formed?" << endl; cout << "x = "; cin >> q1ax; cout << endl << "y = "; cin >> q1ay; cout << endl; if (q1ax == (q1x + q1vx) && q1ay == ( q1y + q1vy)) { cout << "Correct! Next Question..." << endl << endl; QuestionTwo (); } else { cout << "Incorrect! Please try again" << endl << endl; QuestionOne (); } } void QuestionTwo () { int q2x, q2y, q2ax, q2ay; q2x = rand() % 10 + 1; q2y = rand() % 10 + 1; q2ax = q2y; q2ay = q2x; cout << "Point " << q2x << ", " << q2y << "is being rotated 90 degrees clockwise." << endl << "What are the coordinates after the rotation?" << endl << endl; cout << "x = "; cin >> q2ax; cout << endl << "y = "; cin >> q2ay; cout << endl; if (q2ax == q2y && q2ay == q2x) { cout << "Correct!" << endl << endl; } else { cout << "Incorrect! Try again..." << endl << endl; QuestionTwo(); } } int main() { srand(time(0)); cout << "Geometry Chapter 9" << endl << endl; QuestionOne (); system ("pause"); return 0; } ``````

Is this what you mean by forward declaring? Because this didn't work but I might have done it wrong. Thanks for the help
It is `<iostream>` and your code works fine for me (aside from wrong answer calculation in QuestionTwo). Might be something in your project settings. Try to create a new project and copy code there.
Last edited on
Hmm..still getting "1 failed" even with a new project I'm using Visual Express C++ 2010. What settings should I have? And I thought that when you rotate a point with positive coordinates the x and y values switch?
IT WORKED! My problem was that I checked the "Use precompiled header". Thank you so much MiiNiPaa!
Topic archived. No new replies allowed.