converting numbers to letters

Apr 20, 2012 at 3:46am
hello im trying to do a program that converts numbers to letter for example if the number is betwen 90 to 100 the letter would be 'A' if its 80 to 89 the letter would be 'B' and so on can someone help me please.
Apr 20, 2012 at 3:48am
You already answered your own question.

1
2
3
4
if (number >= 90 && number <= 100)
{
    letter = 'A';
}
Apr 20, 2012 at 4:07am
it doesnt show the letter it only change my calculations i did a short program to just start it and it show me as a result 65 not an A can you please check it out thank you.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main()
{
double midExam, finExam, aveAssign, finGrade;
char A;
char lName[15];
cout <<""<<endl;
cout <<" Please enter student's last name: ";
cin >> lName;
cout <<" Please enter student's midterm exam grade: ";
cin >> midExam;
cout <<" Please enter student's final exam grade: ";
cin >> finExam;
cout <<" Please enter student's average Assignment grade: ";
cin >> aveAssign;

finGrade = 0.35*midExam + 0.3*aveAssign + 0.35*finExam;

if (finGrade>=90 && finGrade <=100)
{
finGrade = 'A';
}
cout <<setw(10)<<lName<<setw(15) <<finGrade<<endl;


system("pause");
return 0;
}
Apr 20, 2012 at 4:10am
Because finGrade is a double, it will show the ascii number of 'A'

It should be obvious that if you want to display a character to the screen, you need to display a character. In your example, finGrade is not a character, it is a double.
Apr 20, 2012 at 4:11am
You need to make a new variable.

char finLetterGrade;

then set finLetterGrade to 'A' and then display it instead of finGrade.
Apr 20, 2012 at 4:24am
got it thanks
Topic archived. No new replies allowed.