Using int and string?

In my function find_lettergrade I need to determine a grade based off of the score entered. I also need to determing a sign. if the grade is the an 79,89, or 99 the grade should be C+ B+ and A+ respectively. I can get my program to determine a grade, the issue is that I am trying to determine the sign based off of the second character in the score (if it is a nine make sign a plus). The problem is I dont think I can do the whole score.at thing with and integer value of score. I tried changing it to string, but then I cant find the letter grade. Any suggestions?
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
#include <iostream>
#include <string>
using namespace std;
void find_lettergrade(int,char&,char&);
int score;
char grade;
char sign;
int main()
{
cin>> score;
find_lettergrade(score,grade,sign);
cout << grade << endl;
}
void find_lettergrade (int score, char& grade, char& sign )
{
	if ((score<80)&&(score>69))
	{
grade = 'D';
}

if(score.at(1)='9'){
	sign== '+';

}
}
can you use a simple switch statement?
Last edited on
I could but how would that let me use score as a string ( in order to use .at(1)) and use it as an integer to find the grade?
Essentialy I am just trying to use the .at function (or whatever it is called) with an integer value. Is this only possible for strings? Is there a workaround?
A switch wouldn't help because you'd have to make so many cases and you wouldn't be able to cover decimal values.

Here's what you need to do to get a sign:
1
2
if (score%10 == 9)
  sign = '+';


This tells us that if the remainder of score/10 is 9 (the last digit is a 9), then add a plus.

Note in line 21 and 22 above, you used the comparison operator == instead of the assignment operator = and vice versa. This is a mistake.
thanks so much


Last edited on
Topic archived. No new replies allowed.