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’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
// ax + b = c linear equation calculator.
#include <iostream>
#include <string>
#include <sstream>
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: |
---|
1 2
|
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.