You are using a version without Ads of this website. Please, consider donating:

### error: expected ‘;’ before... - need help with error.

Hello.

Please tell me, what piece of code is causing this error:

prog.cpp: In function ‘int main()’:
prog.cpp:73:6: error: expected ‘;’ before ‘correct_equation_validation’
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091`` ``````// ax + b = c linear equation calculator. #include #include #include int main() { std::string a_var_s; long double a_var = 0; std::string b_var_s; long double b_var = 0; std::string c_var_s; long double c_var = 0; std::string correct_equation; std::string correct_equation_validation; long double right_side = 0; long double res = 0; std::string use_again; do { std::cout << "\n"; std::cout << "This program solves linear equations in the ax + b = c form.\n"; std::cout << "Example: 5x + 4 = 9. This program will calculate what the variable (x) equals.\n"; while ( correct_equation != "y" || correct_equation != "Y" ) { std::cout << "Input the value of a:\n"; std::getline ( std::cin, a_var_s ); std::stringstream( a_var_s ) >> a_var; std::cout << "Input the value of b:\n"; std::getline ( std::cin, b_var_s ); std::stringstream( b_var_s ) >> b_var; std::cout << "Input the value of c (the constant):\n"; std::getline ( std::cin, c_var_s ); std::stringstream( c_var_s ) >> c_var; std::cout << "Did you mean to input:\n"; std::cout << a_var << "x"; if ( b_var >= 0 ) std::cout << "+" << b_var; else std::cout << b_var; std::cout << c_var << ".\n"; std::cout << "\n"; do { std::cout << "Input 'y' if correct or 'n' if incorrect:\n"; std::cin >> correct_equation; if ( correct_equation != "y" || correct_equation != "n" || correct_equation != "Y" || correct_equation != "N" ) { std::cout << "Invalid user input.\n"; correct_equation_validation = "n"; } else if ( correct_equation == "n" || correct_equation == "N" ) correct_equation_validation = "y"; else ( correct_equation == "y" || correct_equation == "Y" ) correct_equation_validation = "y"; } while ( correct_equation_validation != "y" ); } if ( b_var >= 0 ) right_side = c_var - b_var; else right_side = c_var + b_var; res = right_side/a_var; std::cout << res; std::cout << "Input 'y' to use this program again:\n"; } while ( use_again == "y" || use_again == "Y" ); return 0; } ``````
Last edited on
Gerrit1 wrote:
 ``12`` `````` else ( correct_equation == "y" || correct_equation == "Y" ) correct_equation_validation = "y";``````
I think you mean "else if" - "else" does not take a condition.
Of course, I did not see that.

Thank you.
Topic archived. No new replies allowed.