hello guys...
can you help me to find coding for grading system for my new assingment...( grade n grade point)
grade A= 4.00
A- = 3.70
B+ = 3.50
B = 3.00
B- = 2.67
C+ =2.50
C = 2.00
C- = 1.67
D+ = 1.33
D = 1.00
E = 0.00
its must cout for the grade point..when the user/students enter the grade,the cout must be the grade point??did you get my question...I'm a malay student so my english is not very well...

this what I've done so far but it doesnt work..

/* Program to find out students grade pointer*/
#include<iostream.h>
void main()
{
char grade[2];
//grade  = 0;
cout<< " please enter your grade : ";
{
if (grade =="A")
cout<< grade;//4.00";
else if (grade =="A-")
cout<< "3.70";
else if (grade == "B+")
cout<< "3.50";
else if (grade == "B")
cout<< "3.00";
else if (grade == "B-")
cout<< "2.67";
else if (grade == "C+")
cout<< "2.50";
else if (grade == "C")
cout<< "2.00";
else if (grade == "C-")
cout<< "1.67";
else if (grade == "D+")
cout<< "1.33";
else if (grade == "D")
cout<< "1.00";
else if (grade == "E")
cout<< "0.00";
}
//return 0;
}

Dani AI

Generated

The thread goal is to accept a letter grade (like A, B+, A-) and print its numeric grade point. The original post code never reads input, uses char/char[] for multi-character grades, compares incompatible types, and uses old headers and void main. rightly asked where input is taken; exposed the common pitfall that a single char will only look at the first character; and correctly recommended std::string, int main() and modern headers.

A robust, clear approach: store the mapping in a std::unordered_map<std::string,double>, read the whole input as a std::string (use std::getline or std::cin >>), trim whitespace and normalize case, then look up the normalized key in the map and print the value with std::fixed + std::setprecision(2). This avoids brittle character comparisons and makes the mapping easy to maintain (add/remove grades later). Validate the lookup and print a friendly error when the grade is unknown.

Example implementation (modern, standard C++11+):

#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <iomanip>

static std::string normalize(std::string s){
    s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch){ return !std::isspace(ch); }));
    s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch){ return !std::isspace(ch); }).base(), s.end());
    std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c){ return std::toupper(c); });
    return s;
}

int main(){
    std::unordered_map<std::string,double> gp = { {"A",4.00}, {"A-",3.70}, {"B+",3.50}, {"B",3.00},
        {"B-",2.67}, {"C+",2.50}, {"C",2.00}, {"C-",1.67}, {"D+",1.33}, {"D",1.00}, {"E",0.00} };

    std::string grade;
    std::cout << "Enter letter grade: ";
    if (!std::getline(std::cin, grade)) return 0;
    grade = normalize(grade);

    auto it = gp.find(grade);
    if (it != gp.end()) std::cout << std::fixed << std::setprecision(2) << it->second << '\n';
    else std::cout << "Invalid grade\n";
    return 0;
}

Troubleshooting notes: avoid char for multi-character input; comparing char to string literals is wrong; use <iostream> (not <iostream.h>) and int main(); when expanding to multiple courses, multiply each grade point by course credits, sum, then divide by total credits for GPA.

Recommended Answers

All 3 Replies

Where did you accept the grade?

This should work . But if you enter the word "Alfa" it says that your grade is "4.00" . Good Luck Debugging it , i ain't doing your whole homework

#include <iostream.h>

char grade;
int i=1;

int main(){
 do{
 cout<< "Enter Grade : ";cin>>grade;
 if (grade == 'A'){cout<< "4.00";i=0;}
 if (grade == 'A-'){cout<< "3.70";i=0;}
 if (grade == 'B+'){cout<< "3.50";i=0;}
 if (grade == 'B'){cout<< "3.00";i=0;}
 if (grade == 'B-'){cout<< "2.67";i=0;}
 if (grade == 'C+'){cout<< "2.50";i=0;}
 if (grade == 'C'){cout<< "2.00";i=0;}
 if (grade == 'C-'){cout<< "1.67";i=0;}
 if (grade == 'D+'){cout<< "1.33";i=0;}
 if (grade == 'D'){cout<< "1.00";i=0;}
 if (grade == 'E'){cout<< "0.00";i=0;}
 if(i==1)cout<<"Wrong Grade"<<endl;
 }while(i==1);
}
commented: We do NOT give working answers on this forum. Whe HELP them find their own answers. -2

I would use string grade; instead of char grade; , so that you can have the - or + with it. A char represents one character.

Also, why don't you use int main() instead of void main() ? And you probably want #include<iostream> instead of #include<iostream.h> .

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.