Getting errors and can't figure out why. PLZ HELP

My program is supposed to read input from a txt file, process it, do some calculations, and output to a txt file.

This is what I have:

#include "resistors.h"
#include <fstream>

using std::endl;
using std::ifstream;
using std::ofstream;
using std::string;


void computeResistance()
{
ifstream in("input.txt");
ofstream out("output.txt");
double r1, r2, r3;
double R;

in >> r1 >> r2 >> r3;

while( !in.fail() )
{
if r1 && r2 && r3 !== 0;
{
R = (1 / ((1/r1)+(1/r2)+(1/r2)));
out << R << endl;
}
else if r1 || r2 || r3 == 0;
{
out << "--error--" << endl;
}
}
in.close(); //close the input file since were done with it.
out.close(); //close the output file since were done with it.
}

AND THESE ARE THE ERRORS I AM GETTING:

Line(21): error C2061: syntax error: identifier 'r1'
Line(26): error C2181: illegal else without matching if
Line(26): error C2061: syntax error: identifier 'r1'


any help would be appreciated. thanks
Last edited on
1
2
3
if( condition ){
   statements
}

note the parenthesis and the lack of semicolon before the braces

to check inequality, use != or not_eq

if( r1 || r2 || r3 == 0 )
would be evaluated as if( (r1) or (r2) or (r3==0) ), a number is evaluated as true if it is not 0.
got it! thanks for the help
Topic archived. No new replies allowed.