Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
C program problem
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-05-2012, 08:14 PM
fball56's Avatar
Active Member
 
Join Date: Nov 2011
Location: Purdue
Posts: 179
Default 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.
Reply With Quote
  #2  
Old 02-06-2012, 12:21 AM
Darthatron's Avatar
Massive Troll
Ex-Moderator Visual Basic Programmers
 
Join Date: May 2006
Location: The internet.
Posts: 1,604
Send a message via MSN to Darthatron
Default Re: 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.
__________________
I do not trade.
Always ask for a PM.
Reply With Quote
  #3  
Old 02-06-2012, 12:46 AM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: 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.
__________________

Reply With Quote
  #4  
Old 02-06-2012, 12:58 AM
fball56's Avatar
Active Member
 
Join Date: Nov 2011
Location: Purdue
Posts: 179
Default Re: 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.
Reply With Quote
  #5  
Old 02-06-2012, 02:06 AM
Guru
 
Join Date: Jun 2005
Location: Canada
Posts: 1,844
Default Re: 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.
__________________

Reply With Quote
  #6  
Old 02-06-2012, 02:22 AM
fball56's Avatar
Active Member
 
Join Date: Nov 2011
Location: Purdue
Posts: 179
Default Re: C program problem

Quote:
Originally Posted by blindkilla View Post
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?
Reply With Quote
  #7  
Old 02-06-2012, 03:19 AM
Darthatron's Avatar
Massive Troll
Ex-Moderator Visual Basic Programmers
 
Join Date: May 2006
Location: The internet.
Posts: 1,604
Send a message via MSN to Darthatron
Default Re: 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]
__________________
I do not trade.
Always ask for a PM.
Reply With Quote
  #8  
Old 02-07-2012, 02:56 AM
fball56's Avatar
Active Member
 
Join Date: Nov 2011
Location: Purdue
Posts: 179
Default Re: 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!!
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 05:58 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1