wrong code

what is wrong in the following code ??

#include<iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
using namespace std;

int main()
{
int g1,g2,g3,num1,num2,num3;
double average_of_numeric_grades;
char letter_grade1,letter_grade2,letter_grade3;
int percentile_average;



ifstream infile1;
infile1.open("C:\\C++\\grades.txt");
infile1 >> g1 >> g2 >> g3;
infile1.close;


num1=g1;
if (90<=num1 && num1<=100)
{letter_grade1='A';
}
else if (80<=num1 && num1<=89)
{letter_grade1='B';
}
else if (70<=num1 && num1<=79)
{letter_grade1='C';
}
else if (60<=num1 && num1<=69)
{letter_grade1='D';
}
else if (num1<60)
{letter_grade1='E';
}

num2=g2;
if (90<=num2 && num2<=100)
{letter_grade2='A';
}
else if (80<=num2 && num2<=89)
{letter_grade2='B';
}
else if (70<=num2 && num2<=79)
{letter_grade2='C';
}
else if (60<=num2 && num2<=69)
{letter_grade2='D';
}
else if (num2<60)
{letter_grade2='E';
}
num3=g3;
if (90<=num3 && num3<=100)
{letter_grade3='A';
}
else if (80<=num3 && num3<=89)
{letter_grade3='B';
}
else if (70<=num3 && num3<=79)
{letter_grade3='C';
}
else if (60<=num3 && num3<=69)
{letter_grade3='D';
}
else if (num3<60)
{letter_grade3='E';
}
percentile_average==(g1+g2+g3)/3;
cout<<"the percentile average is:"<<percentile_average<<endl;
cout<<"the letter grades are:"<<letter_grade1<<" "<<letter_grade2<<" "<<letter_grade3<<endl;

return 0;

}
The lack of [code] tags.
Take a very close look at the conditions:
if (90<=num1 && num1<=100)

If num1 is 85, what happens? Is that what you expect?
If num1 is 90, what happens? Is that what you expect?
If num1 is 95, what happens? Is that what you expect?
If num1 is 100, what happens? Is that what you expect?
If num1 is 105, what happens? Is that what you expect?
what are they?
if the numbers are written as follow in the file : 89 79 69...how can the program read the space and ignore it , in other words , how can we use cin.ignore() and cin.get() here??
What kind of output are you getting?

if the numbers are written as follow in the file : 89 79 69...how can the program read the space and ignore it , in other words , how can we use cin.ignore() and cin.get() here??

Since you've declared your variables (g1, g2, and g3) as "int" when pulling the number into the data stream it shouldn't be taking the spaces since it will only accept numbers. It should be ignoring it already.

percentile_average==(g1+g2+g3)/3;
Also, "==" isn't want you want to be using here. You need just the single "=" to assign "percentile_average" the value being calculated. It will also be showing up as a decimal, so you need to multiply it by 100 in order for "percentile_average" to hold the value since it is declared as an "int" not "float".
Last edited on
Topic archived. No new replies allowed.