-6

I'm quite confused with this question. Can anyone enlighten me?

The question is:

Write a function that converts a char letter grade into its numerical equivalent. Use the grading system below. A=4.0 B=3.0 C=2.0 D=1.0 F=0.0

To receive full credit your answer must use a switch statement. In case when the function receives a character that is not A,B,C,D,F, return value 0.0. The prototype is below:

double gradeNum(char grade)
{ //your code here

//This is my coding

#include<iomanip>
#include<iostream>
#include<string>
using namespace std;
double gradeNum(char grade);
int main ()
{   
 char grade;
 cout<<"Please enter your grade;"<<endl;
 cin>>grade;
 double output=gradeNum(grade);
 cout<<output;
 return 0;  
}

double gradeNum(char grade){
    
switch (grade){
    case 'A':
        return 4.0;
        break;
    case 'B':
        return 3.0;
        break;
    case 'C':
        return 2.0;
        break;
    case 'D':
        return 1.0;
        break;
    case 'F':
        return 0.0; 
        break;  
    default:
        return 0.0;
        break;          
}
    

    
}
Community
  • 1
  • 1
  • 1
    A switch statement in main won't help the function do its job. – StoryTeller - Unslander Monica Nov 28 '18 at 08:17
  • Did you try solving it yourself? What problems are you encountering? – Rafael Nov 28 '18 at 08:17
  • _Write a function..._ Why would you worry about main? – perivesta Nov 28 '18 at 08:18
  • 1
    Welcome to SO. Please provide a Minimal, Complete, and Verifiable example. **Show us the code for your latest attempt** and where you got stuck. and explain why the result is not what you expected. Edit your question to include the code, please don't add it in a comment, as it will probably be unreadable. https://stackoverflow.com/help/mcve It is better to show what is actually happening, rather than describing what you expect to happen. Please include code and output as content for your question, not as pictures or external links. – Dragonthoughts Nov 28 '18 at 08:23
  • 1
    Read the problem statement carefully. You should not have `main` at all. – molbdnilo Nov 28 '18 at 08:24
  • Obviously the `switch` should go into the `gradeNUm` function. You'll have something like `switch (grade) {case 'A': ...; case 'B': ...}` – Jabberwocky Nov 28 '18 at 08:24
  • yes,i did tried to code it.The problem is everytime i execute the program.The numerical value is in integer not double. – Jhazaline Johny Nov 28 '18 at 09:31
  • @JhazalineJohny your code is fine. Be aware that e.g. `3` _is_ also a `double` value. Maybe you're looking for [this SO article](https://stackoverflow.com/questions/5907031/printing-the-correct-number-of-decimal-points-with-cout) – Jabberwocky Nov 28 '18 at 10:16

1 Answers1

0

The switch statement should be in the function "gradeNum()". From main you should call the above function with a specific input. For example:

int main()
{
   ...
   double output = gradeNum('A');
   ...
}
double gradeNum(char grade)
{ 
   switch (grade)
   {
     case 'A':
       return 4.0;

    case 'B':
       return 3.0;

   ....

   }

}