• Log in or sign up for an account here: https://www.sythe.org/login

C program problem

fball56

Active Member
Joined
Nov 8, 2011
Sythe Gold
0
Messages
179
Location
Purdue
C program problem
I have an assignment to input grades and then output the letter grade for whatever is input. So if i would input 65 then the score is 65/100 or 65% and would be a D. And a 90 would be an A. My question is how to produce a letter when a number is input? I can not use if then statements. If I do then I get a zero on the assignment. I am lost on how else to do it.

Thank you.
 
C program problem
Is this for C++, or C#? They are completely different languages. Your last problem was for C++, so that's why I'm asking.
 
C program problem
Regardless of what language he is using, the functionality the he is seeking will be the same regardless of whether he uses C, C++, or C# for this.

Easiest way to do it is to just use if statements like so.

Code:
if (score == 65)
{
      //letter grade is D
}
else if (score is < 65)
{
     //letter grade is F
}

Hopefully you get the idea. You can also check for a range like this:

Code:
if (score is < 100 && score > 70) { ... }

Good luck, if you need any more help let me know.
 
C program problem
Thanks but my original post said I can't use if then statements or if else. Same thing. And its just C as far as I know lol. All the class material just says C programming.
 
C program problem
My mistake. Well the only other way I can think of doing this is to use a hash table or multi dimensional array. But that would only work if you know the exact grade (it wouldnt work for ranges).

Store it something like this, variable["65"]["D"] if you're using a multi dimensional array. Then you can just go, variable[score][0] and get the letter D, but that's not a very good way of doing it.

If/else would be the best option if you were allowed to use them.
 
C program problem
My mistake. Well the only other way I can think of doing this is to use a hash table or multi dimensional array. But that would only work if you know the exact grade (it wouldnt work for ranges).

Store it something like this, variable["65"]["D"] if you're using a multi dimensional array. Then you can just go, variable[score][0] and get the letter D, but that's not a very good way of doing it.

If/else would be the best option if you were allowed to use them.

ok. I'm not allowed to use them. So the way I have to do it is I run the program and then i have to input a grade for whatever the grade is. So what would the program look like?
 
C program problem
It's just cruel to not let you use an If Statement for something like this. But I think your best option would be to create an array of letters.

Code:
	char letter[101];
	int i = 0;
	for (i; i < 60; i++)
	{
		letter[i] = 'F';
	}
	for (i; i < 65; i++)
	{
		letter[i] = 'D';
	}
	for (i; i < 75; i++)
	{
		letter[i] = 'C';
	}
	for (i; i < 90; i++)
	{
		letter[i] = 'B';
	}
	for (i; i <= 100; i++)
	{
		letter[i] = 'A';
	}

Then get the letter from the array
Code:
std::cout << letter[grade]
 
C program problem
Hey I just wanna let you guys know how I solved it.
I went and got help from a TA fyi. I didn't get this on my own lol
Code:
int letter(int a)
{
  int x;
  x = (70 - (( a / 55) * 2) - ( a / 65) - ( a / 75) - ( a / 85));
  return(x);
}
So this outputs the ascii code for the letter and then it displays the right letter.

Thanks so much for the help though!!
 
Runescape Gamblingrunescape gambling
Back
Top