I need help with this program. here is what we are supposed to do.
The program should prompt the user to 'Please enter numeric grade: '.

The program will then pass the numeric grade to a function that will convert to a letter grade. This function should have the following prototype:

char get_letter_grade (int grade_num); 

100-90 A

89-80 B

79-70 C

69-60 D

below 60 F
  1. The character that is returned will then be sent to a function to determine if the letter grade is passing (grades higher than 59 are passing). This function should have the following prototype:

    bool is_passing(char grade_letter);

  2. Your program should then display the results. For example:

    Please enter numeric grade: 83

    The letter grade is: B.
    The grade is passing.

Here is what i have so far.

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
    int grade_num;

    cout<< "Please enter numeric grade:"<< endl;
    cin>> grade_num;
return 0;
}

char get_letter_grade (int grade_num)

{
    if (grade_num<=60);
        cout<< "The letter grade is F"<< endl;
    else if ( grade_num<=69);
        cout<< "The letter grade is D"<< endl;
    else if (grade_num<=79);
        cout<< "The letter grade is C"<< endl;
    else if (grade_num<=89);
        cout<< "The letter grade is B"<< endl;
    else (grade_num<=100);
        cout<< "The letter grade is A"<< endl;
return (grade_num);
}

bool is_passing(char grade_letter)

{

Recommended Answers

All 21 Replies

Please use code tags
Remeber you are working with a specific range so you are going to need to use the && in your get letter grade function. Also that function needs some other adjustments. You also need to call it from main. Did you even go to class?

the answer to this is in my old C++ book, it has the same questions as an example

i don't have to book with me, but i'll try to put it up tomorrow

This solution won't work for you, but it should give you a push in the right direction:

#include <iostream>

using namespace std;

char letter_grade(int grade_num)
{
  char limit[][4] = {90,80,70,60,'A','B','C','D'};

  for (int i = 0; i < 4; i++) {
    if (grade_num >= limit[0][i])
      return limit[1][i];
  }

  return 'F';
}

bool is_passing(char grade_letter)
{
  return grade_letter < 'F'; // Portability is for wusses
}

int main()
{
  for (int i = 0; i < 101; i++) {
    cout<< i <<" = "<< letter_grade(i) <<": ";
    cout<< boolalpha << is_passing(letter_grade(i)) <<endl;
  }
}

I'd like to point out that these solutions are no better or worse than anyone elses, but rather a demonstration of different ways to solve the problem and still get the same result.

char get_letter_grade (int grade_num) 
{
char Result;
 
switch (grade_num / 10)
	{
	case 10:
	case 9:
	 Result = 'A';
	 break;
 
	case 8:
	 Result = 'B';
	 break;
 
	case 7:
	 Result = 'C';
	 break;
 
	case 6:
	 Result = 'D';
	 break;
 
	default:
	 Result = 'F';
	}
 
return Result;
}

or Needs tweeking if grade is 100 or less then 60

char get_letter_grade (int grade_num)
 
{
return ((10 - (Grade / 10)) + 64);
}

Thanks for all of the help. We get little to no help from the TA's in our classes and yes i do go to class, it's hard to learn when they do not teach what you need to know.

You realize you're paying to be taught, right? Don't just sit there and whine about the instructors not doing their part, make them do it.

You realize you're paying to be taught, right? Don't just sit there and whine about the instructors not doing their part, make them do it.

ONE HELL OF A POINT...i'll have to remember that "intensely" if i get accepted to grad school

Thanks for all of the help. We get little to no help from the TA's in our classes and yes i do go to class, it's hard to learn when they do not teach what you need to know.

int main(){

int grade;

grade = 0;

cout << "Enter grade: ";
cin >> grade;

{
if (grade >= 90)
cout << "A";
else if (grade >= 80)
cout << "B";
else if (grade >=70)
cout << "C";
else if (grade >= 60)
cout << "D";
else
cout << "F";
}
return 0;
}

i don't know if that will work, its been way to long since writing code

>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.

To this day, I still test my code before posting it 9 times out of 10. I'm confident that it's flawless (though part of that is ego), but I still would rather double and triple check myself than have somebody else correct a stupid mistake.

>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.

i use public computers i don't have one of my own :cry:

trust me, if i could i'd be compiling running, and editing aaaaaaall day

*wonders if it would work*

>use public computers i don't have one of my own
Blah blah blah, stop making excuses and start finding solutions. Here's one.

>*wonders if it would work*
No, it wouldn't.

*wonders if it would work*
No, it wouldn't.

I beleive you're referring to code. If so, what about it won't work. The only thing I could see in the last snippet was it's not really necessary to enclose the set of conditionals in a statement block.

>use public computers i don't have one of my own
Blah blah blah, stop making excuses and start finding solutions. Here's one.

:cheesy:

im currently working on a program to hack into your mind, or at least the part that stores programming knowledge

>i don't know if that will work
So run it and see. If you aren't confident that your code is 100% correct, don't write directly to the thread. Write the code in an editor, compile it, run it, debug it, and make sure it's working like you expect before posting it.

#include <iostream>

int main(){

int grade;

grade = 0;

std::cout << "Enter grade: ";
std::cin >> grade;

if (grade >= 90)
std::cout << "A";
else if (grade >= 80)
std::cout << "B";
else if (grade >=70)
std::cout << "C";
else if (grade >= 60)
std::cout << "D";
else
std::cout << "F";

return 0;
}

Narue,

I'm sorry i temporarily lost it back there :rolleyes:

thanks for the link, the code above has been compiled successfully, i don't know where i could run a test on it, but its error less.

*still trying to figure out your example*

>If so, what about it won't work.
iostream? namespace?

>If so, what about it won't work.
iostream? namespace?

i left that out thinking it was a "given"

when i went to compile it i used <iostream.h> and got an error back

*can't believe he's coding again thanks to this site and you*

but anyway, i took the ".h" off and compiled again, another error came up

it didn't recognize "cout" and "cin" saying they wasn't "standard"

i added "std::" (haven't used that in a while) and it compiled successfully

i didn't have to add "using namespace std;" like you did though, wonder why!?!?!?

>i left that out thinking it was a "given"
You'd be surprised at how many people won't see it that way. If you post code that could be mistaken for a complete program, make sure it compiles and runs as is.

>i didn't have to add "using namespace std;" like you did though, wonder why!?!?!?
Because you qualified each standard name with std::. There are three ways to qualify names in a namespace. Opening up the entire namespace like I did is one way and handling names on a case by case basis like you did is another. The third way is with a using declaration:

#include <iostream>

// Only allow cout and endl as unqualified names
using std::cout;
using std::endl;

int main()
{
  cout<<"Hello, world!"<<endl;
}

>i didn't have to add "using namespace std;" like you did though, wonder why!?!?!?
Because you qualified each standard name with std::. There are three ways to qualify names in a namespace. Opening up the entire namespace like I did is one way and handling names on a case by case basis like you did is another. The third way is with a using declaration:

#include <iostream>

// Only allow cout and endl as unqualified names
using std::cout;
using std::endl;

int main()
{
  cout<<"Hello, world!"<<endl;
}

that's right :!:

i forgot about all that stuff, you're absolutly right, you are definitely a God sent woman

thanx for bring that back to memory

Here is what I've created. I have compiled it and it is legit. I'm not sure if this includes what you wanted but feel free to modify it.

#include <iostream>

using namespace std;


int main()
{
    int grade;

    cout << "Input your grade (0-100): ";
    cin >> grade;
    cout << endl;

    if (grade == 100){
       cout << "You got a perfect grade!" << endl;
       cout << "Letter grade: A" << endl;
        }
    else if (grade >=90 && grade <=100){
        cout << "Letter grade: A" << endl << endl;
        }
    else if (grade >=80 && grade <=89){
        cout << "Letter grade: B" << endl << endl;
        }
    else if (grade >=70 && grade <=79){
        cout << "Letter grade: C" << endl << endl;
        }
    else if (grade >=60 && grade <=69) {
        cout << "Letter grade: D" << endl << endl;
        }
    else if (grade < 60) {
        cout << "Letter grade: F" << endl << endl;
        }
    else {
        cout << "Invalid grade!" << endl;
    }

    system("pause");
    return 0;
}
commented: Five YEARS too late. -4
commented: Don't bump old threads or give away code -1

int main(){

int grade;

grade = 0;

cout << "Enter grade: ";
cin >> grade;

{
if (grade >= 90)
cout << "A";
else if (grade >= 80)
cout << "B";
else if (grade >=70)
cout << "C";
else if (grade >= 60)
cout << "D";
else
cout << "F";
}
return 0;
}

i don't know if that will work, its been way to long since writing code

Question::: what if you input a grade 100 above?? or a negative integers?? what it should be??you must do it with limitation just like this, .

#include <iostream.h>
int grade;
main()
{
cout<<"Enter a Grade: ";
cin>>grade;
if(grade>94)
if(grade<101)
cout<<"Rating A";
if(grade>89)
if(grade<95)
cout<<"Rating B";
if(grade>84)
if(grade<90)
cout<<"Rating C";
if(grade>79)
if(grade<85)
cout<<"Rating D";
if(grade>74)
if(grade<80)
cout<<"Rating E";
if(grade<75)
if(grade>0)
cout<<"Rating F";
if(grade<1)
cout<<"Out Of Range";
if(grade>100)
cout<<"Out Of Range";
}


or like this


#include <iostream.h>
int grade;
main()
{
cout<<"Enter a Grade: ";
cin>>grade;
if((grade>94) && (grade<101))
cout<<"Rating A";
if((grade>89) && (grade<95))
cout<<"Rating B";
if((grade>84) && (grade<90))
cout<<"Rating C";
if((grade>79) && (grade<85))
cout<<"Rating D";
if((grade>74) && (grade<80))
cout<<"Rating E";
if((grade<75) && (grade>0))
cout<<"Rating F";
if(grade<1)
cout<<"Out Of Range";
if(grade>100)
cout<<"Out Of Range";
}

#include<stdio.h>
#include<string>
#include<conio.h>

int main()
{
    char name[50];
    char clas[50];
    int a;
     printf("\n\n\tGrade Calculator");
    printf("\n\nEnter Your Name:");
    fgets(name,50,stdin);
    printf("\nEnter Your Class:");
    fgets(clas,50,stdin); 
     printf("\nHello Mr.%s",name);
     printf("\nYour class is %s",clas);
     printf("\nPlease Enter Your Marks:");
     scanf("%d",&a);
    if(a<=30){printf("\nYour are Fail");}else{printf("");};
    if(a>=31&&a<=49){printf("\nYour Grade is D");} else{printf(" ");};
    if(a>=50&&a<=59){printf("\nYour Grade is C");} else{printf(" ");};
    if(a>=60&&a<=79){printf("\nYour Grade is B");} else{printf(" ");};
    if(a>=80&&a<=100){printf("\nYour Grade is A");} else{printf(" ");};
    if(a>=101){printf("\nhehehe...Computer nal Chalakian(@ @)");};
   getch();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.