Hey, what i am trying to do is to write a function that inputs a student's average and returns 4 if a students average is 90-100, 3 if the average is 80-89, 2 if the average is 70-79, 1 if the average is 60-69, and 0 if the average is lower than 60. Test your function with a program that allows multiple student averages to be entered and uses a sentinel to terminate the loop.

what i got now is and it doesnt seem to work whenever i type in 70 it will give me 1 2 but i want just a 2 Thanks

#include <iostream>
using namespace::std;

int qualityPoints(int);

#include <iomanip>

int main()
{
    int marks;
    cout <<"Please enter the students average: ";
    cin >>marks;


    qualityPoints (marks);
    return 0;
}

int qualityPoints (int mark)
{   

    if  (mark == 60,61,62,63,64,65,66,67,68,69){
        cout <<"1";
    }

    else if (mark == 70,71,72,73,74,75,76,77,78,79){

        cout <<"2";
    }

    if (mark == 80,81,82,83,84,85,86,87,88,89){

        cout <<"3";
    }

            return mark;
}

Your function can be written in a much better way using greater than and less than signs, as well as the AND (&&) operator in the if statements. I rewrote your function and ran it successfully:

int qualityPoints (int mark)
{ 

if (mark >= 60 && mark <70){
cout <<"1";
}

else if (mark >= 70 && mark <80){

cout <<"2";
}

else if (mark >= 80 && mark <90){

cout <<"3";
}

return mark;
}

This tests if the input average falls within a specific range of numbers instead of testing for each number as you had originally tried. Hope this helps.

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.