C programming solver

Write a program to find grace marks for a student using switch. The user should enter the class obtained by the student and number of subjects he has failed in.
• If student gets 1st class and the number of subjects he failed in is greater than 3, then he does not get any grace. If the number of subjects he failed is less than or equal to 3 then grace is of 5 marks per subject
• If the student gets second class and the number of subjects he failed in is greater than 2, then he does not get any grace. If the number of subjects he failed in is less than or equal to 2 then the grace is of 4 marks per subject.
• If the student gets third class and the number of subjects he failed in is greater than 1, then he does not get any grace. If the number of subjects he failed is equal to 1 then the grace is of 5 marks per subject.
8 answers Last reply
More about programming solver
  1. You are definitely new here; we will not do your homework for you ;)

    However, if you give it a good try and have a problem you may post a code sample and we will help then.
  2. What do you not understand specifically?
  3. I'm going to give you some code to start from, if you do not understand this than reply back and I will try to explain it in further detail, the selection structure is a very basic programming concept and also very important so if you don't get this your going to have a real hard time moving to oo programming.
    The switch statement is basically a fancy if statement but im not going to go into detail on this subject, look up control structures for c/c++.

    //your code should be something like this

    int main()
    {

    int classNum; // class is a keyword so it can't be use to name a variable
    int subjectsFailed;
    int grace = 0;

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

    cout << "Enter subjects failed: ";
    cin >> subjectsFailed;

    switch (classNum) // variable to be tested is class
    {
    case 1: // same as if (classNum == 1)
    if (subjectsFailed <= 3) // your next condition to test
    grace = 5; // if true update grace variable
    break; // stops further testing
    case 2:
    if (subjectsFailed <= 2)
    grace = 4;
    break;
    case 3:
    if (subjectsFailed == 1)
    grace = 4;
    break;
    }

    if (grace == 0) // if grace is at default value
    cout << "Student does not recieve grace" << endl;
    else // if grace is anything but 0
    cout << "Student recieves grace of " << grace << "marks per subject."

    return 0;

    }
  4. I'm very disappointed to see an almost complete solution given here. It's not as if it was a difficult problem.

    What help, in the long run, is it going to be to the OP to just copy what has been printed here? With any luck the tutors are smart enough to check sites like this and the guy will get no credit for cheating.
  5. Ijack said:
    I'm very disappointed to see an almost complete solution given here. It's not as if it was a difficult problem.

    What help, in the long run, is it going to be to the OP to just copy what has been printed here? With any luck the tutors are smart enough to check sites like this and the guy will get no credit for cheating.


    Ehhh... Yeah your right, definitely wasn't the most constructive way to explain the selection structure to him but really it's his responsibility to learn it in the long run, hopefully he reviews the code and tries to make since of it.
  6. People who just post their programming questions online (this is literally just the question) aren't interested in learning or "the long run". They are interested in passing some assignment that they don't care about.
  7. randomizer said:
    People who just post their programming questions online (this is literally just the question) aren't interested in learning or "the long run". They are interested in passing some assignment that they don't care about.

    Yep, and then when they graduate with their degree in Computer Science they will get hired by a software company and produce buggy code, which gives all programmers a bad reputation :(

    I helped a woman years ago who wanted to integrate one of my free open source software projects into hers for her final MASTERS project. She had a BS in Computer Science, but she could did not even know where to begin to add a few C source files together using a makefile. . .
Ask a new question

Read More

Programming Switch Apps