Hello all,

I am creating a program, and I am currently stuck. I need someone to guide me on track on what I am doing wrong. My main goal is to get the program to run. I can't even do that. My C++ code is provided below. Thanks for all who helps.

Directions: Write a C++ computer program to compute the grades (assignment scores,lab scores,test scores, final exam score) and find the final grade of what an individual would receive in the class. You must use functions and atleast one must be a value-returning function.

Here is my code:

#include <iostream>
#include <iomanip>

using namespace std;

void testpoints();
void labpoints();
void projectpoints();
void finalpoints();
void finalgrade(double& testpoints, double& labpoints, double& projectpoints,
double& finalpoints);
void printresults (double testpoints, double labpoints, double projectpoints,
double finalpoints);

int main ()
{

    cout<<fixed<<showpoint;
    cout.precision(2);

    double testpoints;
    double labpoints;
    double projectpoints;
    double finalpoints;

    gettestscores();
    getlabscores();
    getprojectscores();
    getfinalexamscores();
    getfinalgrade(testpoints,labpoints,projectpoints,finalpoints);

    printresults(testpoints,labpoints,finalpoints,projectpoints,finalgrade);

    system ("PAUSE");
    return 0;
}

    double gettestscores ()
    {
           int numtest;
           double gettestscores
           double testscores;
           double average;
           double sum = 0;

           cout<<"How many test did you take? "<<endl;
           cin>>numtest;


           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter scores for tests? "<<i<<endl;
               cin>>testscores;

               sum+=testscores;
           }

    }

    double getlabscores ()
    {
           int numlab;
           double labscores;
           double average;
           double sum = 0;

           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;


           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter scores for labs? "<<i<<endl;
               cin>>labscores;

               sum+=labscores;
           }

    }

           double getprojectscores ()
    {
           int numtest;
           double projectscores;
           double average;
           double sum = 0;

           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;


           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter scores for project? "<<i<<endl;
               cin>>projectscores;

               sum+=projectscores;
           }

    }
                double getfinalexamscores ()
    {
           int numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;

           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;


           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for final exam? "<<i<<endl;
               cin>>finalexamscores;

               sum+=finalexamscores;
           }

    }

You have missed a semicolon at the end of this line.

double gettestscores

You can't get your program to run should mean compiler errors or link errors. Next time post the error or warning messages by the compiler if any.

I think the most problems lay in the way you've defined your functions/prototypes.

For example the names & return type are different, for example you list all function prototypes as returning void yet when you actually wrote the function they are set to return type double. You also prototype their names but when you call those functions in main() you call different functions that don't exist.

The printresults function is overloaded, in the prototype you've set it to recieve 4 arguments while in main() you've called the function with 5 arguments. finalgrade is the extra 1 over & that hasn't even been created in main() yet.

When prototyping functions there is no need to add variable names, in fact it should actually be an error to do that since those variables wouldn't exist yet. so those function prototypes should...

A) Match return type
B) Match function call names
C) List only container types for their argument list not variable names.

I'm going to //comment your code below as example, but I'm not changing all (just some of it) your code myself, because of this there could be more errors that I've mentioned in my post... But hey it's a start! :)

#include <iostream>
#include <iomanip>

using namespace std;

void testpoints();
void labpoints();
void projectpoints();
void finalpoints();
void getfinalgrade(double&, double&, double&, double&); /*Function prototype should be closer to this.*/
void printresults (double, double, double, double, double);

int main ()
{
    
    cout<<fixed<<showpoint;
    cout.precision(2);
    
    double testpoints;
    double labpoints;
    double projectpoints;
    double finalpoints;
    //No double finalgrade; here
    

    gettestscores(); //These function calls don't match the prototype names
    getlabscores();
    getprojectscores();
    getfinalexamscores();
    getfinalgrade(testpoints,labpoints,projectpoints,finalpoints);
    
    printresults(testpoints,labpoints,finalpoints,projectpoints,finalgrade);
    
    system ("PAUSE");
    return 0;
}
    
    double gettestscores ()
    {
           int numtest;
           double gettestscores[B];[/B]
           double testscores;
           double average; /*This is an unreferenced variable, you don't seem to have used it not only in this function but not in the other functions neither, are you planning too? If not then take this line out of all the functions except where you actually are going to use it*/
           double sum = 0;
           
           cout<<"How many test did you take? "<<endl;
           cin>>numtest;
           
           
           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter scores for tests? "<<i<<endl;
               cin>>testscores;
               
               sum+=testscores;
           }
           
    }
    
    double getlabscores ()
    {
           int numlab;
           double labscores;
           double average;
           double sum = 0;
           
           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;
           
           
           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter scores for labs? "<<i<<endl;
               cin>>labscores;
               
               sum+=labscores;
           }
           
    }

           double getprojectscores ()
    {
           int numtest;
           double projectscores;
           double average;
           double sum = 0;
           
           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;
           
           
           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter scores for project? "<<i<<endl;
               cin>>projectscores;
               
               sum+=projectscores;
           }
           
    }
                double getfinalexamscores ()
    {
           int numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;
           
           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;
           

           
           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for final exam? "<<i<<endl;
               cin>>finalexamscores;
               
               sum+=finalexamscores;
           }
           
    }

I've changed atleast the function prototypes so they are somewhat more correct... Although I've left them as "void" as I don't know which functions you want to return anything.. Basically change those which should return a value to double leave the others as void. (You'll also need to change the functions return type at their definition, eg if line 7 is "void labpoints" then Line 28 needs to be "labpoints();" & Line 61 needs to be "void labpoints()") Line 42 is missing a semicolon, I've added it in bold in the above code. On line 90 & 93 "numproject" should be "numtest" or numtest on line 84 'numtest' should be made into 'numproject' while line 90 & 93 are left alone.

There are alot of unreferenced variables in your functions that is, you're creating variables but not using them in functions. eg in the last function in your code "double average;" is not used anywhere in that function anywhere out of that function is out of scope.

I've only just noticed aswell 2 of your functions aren't even there

getfinalgrade(testpoints,labpoints,projectpoints,finalpoints);

printresults(testpoints,labpoints,finalpoints,projectpoints,finalgrade);

Those 2 are only prototyped but not in the actual code? (Unless I've missed it)

Unfortunately my post is probably going to seem confusing cause I'm not good as attempting to explain stuff, so short version is, match up function names & return types is the best place to start in my opinion.

Here is my compiler log. Thanks for the reply.


Compiler: Default compiler
Executing g++.exe...

In function `int main()':
:32: error: `gettestscores' undeclared (first use this function)
:32: error: (Each undeclared identifier is reported only once for each function it appears in.)
:33: error: `getlabscores' undeclared (first use this function)
:34: error: `getprojectscores' undeclared (first use this function)
:35: error: `getfinalexamscores' undeclared (first use this function)
:36: error: `getfinalgrade' undeclared (first use this function)
:19: error: too many arguments to function `void printresults(double, double, double, double)'
:38: error: at this point in file

At global scope:
:44: error: `double gettestscores()' used prior to declaration
:45: error: expected unqualified-id before '{' token
:45: error: expected `,' or `;' before '{' token
:66: error: `double getlabscores()' used prior to declaration
:67: error: expected unqualified-id before '{' token
:67: error: expected `,' or `;' before '{' token
:87: error: `double getprojectscores()' used prior to declaration
:88: error: expected unqualified-id before '{' token
:88: error: expected `,' or `;' before '{' token
:107: error: `double getfinalexamscores()' used prior to declaration
:108: error: expected unqualified-id before '{' token
:108: error: expected `,' or `;' before '{' token

Execution terminated

Thanks Yiuca. I'm taking a look at the program now. I appreciate the feedback!

Hey guys, here is my updated code with my compiler errors. I'm having trouble "returning the value".

Compiler errors:

Compiler: Default compiler
Executing  g++.exe...

In function `void testpoints()':
:66: error: return-statement with a value, in function returning 'void'

In function `void labpoints()':
:92: error: return-statement with a value, in function returning 'void'

In function `void projectpoints()':
:115: error: return-statement with a value, in function returning 'void'

In function `void finalexampoints()':
:137: error: return-statement with a value, in function returning 'void'

Execution terminated

In my print results at the bottom of the code is what I would like to print out into the program.

#include <iostream>
#include <iomanip>

using namespace std;

const double test_percent = 0.45;
const double lab_percent = 0.10;
const double project_percent = 0.20;
const double finalexam_percent = 0.25;

void testpoints();
void labpoints();
void projectpoints();
void finalexampoints();
void finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints);
void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

int main ()
{

    cout<<fixed<<showpoint;
    cout.precision(2);

    double testscores;
    double labscores;
    double projectscores;
    double finalexamscores;
    double finalgradescore;

    testpoints();
    labpoints();
    projectpoints();
    finalexampoints();
    finalgrade(testscores,labscores,projectscores,finalexamscores);
    printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);

    system ("PAUSE");
    return 0;
}

    void testpoints ()
    {
           double numtest;
           double testpoints;
           double testscores;
           double average;
           double sum = 0;

           cout<<"How many test did you take? "<<endl;
           cin>>numtest;


           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter score for test #"<<i<<endl;
               cin>>testscores;

               sum+=testscores;
               average = (sum/numtest);
               return (average * test_percent);

           }



    }

    void labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;

           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;


           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;

               sum+=labscores;
               average = (sum/numlab);
               return (average * lab_percent);
           }

    }

           void projectpoints ()
    {
           double numproject;
           double projectscores;
           double average;
           double sum = 0;

           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;


           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter score for project #"<<i<<endl;
               cin>>projectscores;

               sum+=projectscores;
               average = (sum/numproject);
               return (average * project_percent);
           }

    }
           void finalexampoints ()
    {
           double numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;

           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;


           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for Final Exam #"<<i<<endl;
               cin>>finalexamscores;

               sum+=finalexamscores;
               average = (sum/numfinalexam);
               return (average * finalexam_percent);
           }

    }

           void finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
    {

    }
           void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
    {

           double totalpoints;
           double testscores;
           double labscores;
           double projectscores;
           double finalexamscores;
           double finalgrade;

           totalpoints = (testscores + labscores + projectscores + finalexamscores);


           cout<<"Test points: "<<testscores<<endl;
           cout<<"Lab points: "<<labscores<<endl;
           cout<<"Project points: "<<projectscores<<endl;
           cout<<"Final Exam points: "<<finalexamscores<<endl;
           cout<<"Total points: "<<totalpoints<<endl;
           cout<<"Final Grade: "<<finalgrade<<endl;

    }

Prototype & Function return types don't match but other than that it's looking much better! :)

I'll comment the code where you'll need to change, I'll change & comment 1, you just have to do the rest for each of the other errors, as it's the same for each one.

#include <iostream>
#include <iomanip>

using namespace std;

const double test_percent = 0.45;
const double lab_percent = 0.10;
const double project_percent = 0.20;
const double finalexam_percent = 0.25;

double testpoints(); /*This & where you write the actual function needs to be changed, same for rest of functions that turn up the error/have return values*/
void labpoints();
void projectpoints();
void finalexampoints();
void finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints);
void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

int main ()
{
    
    cout<<fixed<<showpoint;
    cout.precision(2);
    
    double testscores;
    double labscores;
    double projectscores;
    double finalexamscores;
    double finalgradescore;
    
    testpoints();
    labpoints();
    projectpoints();
    finalexampoints();
    finalgrade(testscores,labscores,projectscores,finalexamscores);
    printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);
    
    system ("PAUSE");
    return 0;
}
    
    double testpoints () //Change to return type double
    {
           double numtest;
           double testpoints; /*Remove this line it's not used in this function*/
           double testscores;
           double average;
           double sum = 0;
           
           cout<<"How many test did you take? "<<endl;
           cin>>numtest;
           
           
           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter score for test #"<<i<<endl;
               cin>>testscores;
               
               sum+=testscores;
               average = (sum/numtest);
               return (average * test_percent);
               
           }
           
           
           
    }
    
    void labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;
           
           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;
           
           
           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;
               
               sum+=labscores;
               average = (sum/numlab);
               return (average * lab_percent);
           }
           
    }

           void projectpoints ()
    {
           double numproject;
           double projectscores;
           double average;
           double sum = 0;
           
           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;
           
           
           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter score for project #"<<i<<endl;
               cin>>projectscores;
               
               sum+=projectscores;
               average = (sum/numproject);
               return (average * project_percent);
           }
           
    }
           void finalexampoints ()
    {
           double numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;
           
           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;
           
           
           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for Final Exam #"<<i<<endl;
               cin>>finalexamscores;
               
               sum+=finalexamscores;
               average = (sum/numfinalexam);
               return (average * finalexam_percent);
           }
           
    }
    
           void finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
    {
    
    }
           void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
    {
           
           double totalpoints;
           double testscores;
           double labscores;
           double projectscores;
           double finalexamscores;
           double finalgrade; /*finalgrade is redfined here, but overall if you're passing by value & reference you shouldn't need these if you're expecting to use values passed to the function & should only define local variables if you expect them to only be used locally in a function.*/
           
           totalpoints = (testscores + labscores + projectscores + finalexamscores); /*If you meant to use the variables passed into this function then use the variables in the argument list that is use 'testpoints', 'labpoints' that are in the function argument list if that is what you were meaning to do*/
           
           
           cout<<"Test points: "<<testscores<<endl;
           cout<<"Lab points: "<<labscores<<endl;
           cout<<"Project points: "<<projectscores<<endl;
           cout<<"Final Exam points: "<<finalexamscores<<endl;
           cout<<"Total points: "<<totalpoints<<endl;
           cout<<"Final Grade: "<<finalgrade<<endl;
           
    }

In the last function of print results, in the argument list which is

void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)

in bold. The variables are being defined there as the function gets passed the variables from main() so there is no need to redefine them with new names especially considering they'd all be default value & you'd likely always get a printing out of 0 or something similar. I'd assume the values you want to use in there would be those in the argument list, as there is no other real reason to pass the values across.

I'd assume there be more errors/warnings after fixing those, perhaps best to take 1 at a time though, fix those, then work on the next lot that crop up. For example

double labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;
           
           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;
           
           
           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;
               
               sum+=labscores;
               average = (sum/numlab);
               return (average * lab_percent);
           }
           
    }

Not so much an error but more a warning from compiler that there is no return value by default in that function (not all control paths return a value) if for some reason numlab is lower or equal to i before it can even run through the code in that block then in essense it's not returning anything. Could possibly turn up a run-time error or similar.

Thanks for replying again. I applied everything you told me to do except the last 2 parts when you explained about the "final grade" and "total points" part. I didn't quite understand that part. I'm new to C++, so I don't quite understand a lot of the terminology yet. My program runs now (which is a good thing).

After booting up program:

When my program asks "How many tests did you take?"
I answer with "3" (I want to put in 3 test scores)
Then it takes only 1 score, and then goes on to "How many labs did you take?" which only takes 1 lab score. How do I fix this problem?

Also, I'm trying to understand about the final grade and total points part at the bottom.

Here is my updated code:

#include <iostream>
#include <iomanip>

using namespace std;

const double test_percent = 0.45;
const double lab_percent = 0.10;
const double project_percent = 0.20;
const double finalexam_percent = 0.25;

double testpoints();
double labpoints();
double projectpoints();
double finalexampoints();
double finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints);
double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

int main ()
{

    cout<<fixed<<showpoint;
    cout.precision(2);

    double testscores;
    double labscores;
    double projectscores;
    double finalexamscores;
    double finalgradescore;

    testpoints();
    labpoints();
    projectpoints();
    finalexampoints();
    finalgrade(testscores,labscores,projectscores,finalexamscores);
    printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);

    system ("PAUSE");
    return 0;
}

    double testpoints ()
    {
           double numtest;
           double testscores;
           double average;
           double sum = 0;

           cout<<"How many test did you take? "<<endl;
           cin>>numtest;


           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter score for test #"<<i<<endl;
               cin>>testscores;

               sum+=testscores;
               average = (sum/numtest);
               return (average * test_percent);

           }



    }

    double labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;

           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;


           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;

               sum+=labscores;
               average = (sum/numlab);
               return (average * lab_percent);
           }

    }

    double projectpoints ()
    {
           double numproject;
           double projectscores;
           double average;
           double sum = 0;

           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;


           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter score for project #"<<i<<endl;
               cin>>projectscores;

               sum+=projectscores;
               average = (sum/numproject);
               return (average * project_percent);
           }

    }

         double finalexampoints ()
    {
           double numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;

           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;


           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for Final Exam #"<<i<<endl;
               cin>>finalexamscores;

               sum+=finalexamscores;
               average = (sum/numfinalexam);
               return (average * finalexam_percent);
           }

    }

           double finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
    {

    }
           double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
    {

           double totalpoints;
           double testscores;
           double labscores;
           double projectscores;
           double finalexamscores;

           totalpoints = (testscores + labscores + projectscores + finalexamscores);


           cout<<"Test points: "<<testscores<<endl;
           cout<<"Lab points: "<<labscores<<endl;
           cout<<"Project points: "<<projectscores<<endl;
           cout<<"Final Exam points: "<<finalexamscores<<endl;
           cout<<"Total points: "<<totalpoints<<endl;
           cout<<"Final Grade: "<<finalgrade<<endl;

    }

>>How do I fix this problem?

move these two line outside of the for loop.

average = (sum/numtest);
return (average * test_percent);


You only need to do them once. The way you have it you exit the function with the return statement after just one iteration of the loop.

>>I'm trying to understand about the final grade and total points part at the bottom

When a function ends it returns a value, maybe it's nothing, ie, void, maybe it's a double, maybe it's a reference to a stream, maybe it's a user defined type, whatever. The return value can be ignored, as you are doing in all of your functions, or stored in a variable. You have appropriate variables declared to hold the return values of the various functions and then pass those values to the functions that are expecting them.

I'd just add up the return values of all appropriate functions to get a total score and then compare that score to a curve. Maybe it's
100-93 A
92-86 B
85-79 C
78-70 D
<70 F
I don't know what curve you want/need to use is though. I'll leave it up to you to determine how you write the code to determine the grade received.

Thanks for replying again. I applied everything you told me to do except the last 2 parts when you explained about the "final grade" and "total points" part. I didn't quite understand that part. I'm new to C++, so I don't quite understand a lot of the terminology yet. My program runs now (which is a good thing).

It's my bad for assuming you'd understand the terminology used. I'll try to make a quick example of what I mean on the last 2 points.

Here is simply a copy of the code/function with my comments so you don't have to keep scrolling up & down the page too much.

void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
{
 
double totalpoints;
double testscores;
double labscores;
double projectscores;
double finalexamscores;
double finalgrade; /*finalgrade is redfined here, but overall if you're passing by value & reference you shouldn't need these if you're expecting to use values passed to the function & should only define local variables if you expect them to only be used locally in a function.*/
 
totalpoints = (testscores + labscores + projectscores + finalexamscores); /*If you meant to use the variables passed into this function then use the variables in the argument list that is use 'testpoints', 'labpoints' that are in the function argument list if that is what you were meaning to do*/

cout<<"Test points: "<<testscores<<endl;
cout<<"Lab points: "<<labscores<<endl;
cout<<"Project points: "<<projectscores<<endl;
cout<<"Final Exam points: "<<finalexamscores<<endl;
cout<<"Total points: "<<totalpoints<<endl;
cout<<"Final Grade: "<<finalgrade<<endl;
 
}

Starting with re-defined, the variable finalgrade was passed into printresults() near the end you see the last argument double& finalgrade, the other variables you made in there aren't needed however as they would all be created with a default value (usually 0) so what you'd have as output in that function is

Test points: 0
Lab points: 0
etc

Because you're using newly created local variables which are unitialized, that is they have been assigned no values. When you have a function like

void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)

what is happening is in main() where printresults is called, it passes testpoints, labpoints & all the other values, then in printresults, it automatically creates them as you create them, example.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

double printresults(double, double&, int, int&);

int main()
{
	double d_value1 = 58.5;
	double d_value2 = 33.7;
	int i_value1 = 4;
	int i_value2 = 7;
	double ret_value;

	ret_value = printresults(d_value1, d_value2, i_value1, i_value2);

	cout << "d_value1 is: " << d_value1 << endl;
	cout << "d_value2 is: " << d_value2 << endl;
	cout << "i_value1 is: " << i_value1 << endl;
	cout << "i_value2 is: " << i_value2 << endl;
        cout << "ret_value is: " << ret_value << endl;

	cin.get();
	return 0;
}

double printresults(double d_value1, double &d_value2, int i_value1, int &i_value2)
{
	cout << "printresults function-----------------\n";
	cout << "d_value1 is: " << d_value1 << endl;
	cout << "d_value2 is: " << d_value2 << endl;
	cout << "i_value1 is: " << i_value1 << endl;
	cout << "i_value2 is: " << i_value2 << endl;
	cout << "endof printresults output-------------\n";

	d_value1 = d_value1 * 10;
	d_value2 = d_value2 * 5;
	i_value1 = i_value1 * i_value1;
	i_value2 = i_value2 * i_value1;

	return d_value1 * d_value2;
}

Ok so in main() on line 17 as you can see main called the function "printresults" & sends 4 values, 2 by value, 2 by reference, the ones passed by reference are the ones with the ampersand in front of them (&) so basically d_value2 & i_value2 are the values sent by reference, now on line 29 you can see the function & it's argument list, but as you can see in the function itself I have not made anymore doubles or ints, I've simply used the names from that argument list to main multiply those variables in different ways.

So generally what I'm saying is if in the printresults() function I added say added a line to line 37 & added "double d_value1" that would be redefining a variable, since it is already made by the function when it were invoked.

For explaination sake aswell, just incase. If you noticed 2 of the numbers when displayed in main() don't change, while the others 2, if observant, you'll notice that the numbers that change are the ones passed by reference. That is, (double &d_value2, int &i_value2) have changed while (double d_value1, int i_value1) have not. Passing by value only passes by value, the function creates a copy in which you can change the value but the original in main() is not changed, while if you pass by reference you'll be passing the address of the variable & hence changing the actual value in main() which is why the 2 passed by reference show change in main() while the others passed by value are not.

So

totalpoints = (testscores + labscores + projectscores + finalexamscores);

should use the variable names from

double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)

so perhaps it should look more like

totalpoints = (testpoints + labpoints + projectpoints + finalexampoints);

Hope what I meant is a little more clearer to you now.

Lerner answers other question, so not going to repeat! :)

commented: Clearly put a lot of effort into these posts. +6

Thanks for the reply again.

I made some updates to the best of my ability. Took a couple of hours to try to figure out what both of you guys were talking about.

My program still runs, but all of the points come out as "0"

Testpoints: 0
Labpoints: 0
etc.

How do I make the 0 change into the amount that is suppose to be there

Besides that above, I'm going to clarify more of what I'm trying to do....

For example:

When I type the test points in from input, I want the sum of all test points divided by how many scores I put it..Afterwards, I want it to be multiplied by how much the tests combined are worth which is 45%. (which is why I have the formulas below)....A more clear example is below

Lets say, I have test scores of 91, 78, 95. The sum of the test scores would be 264 divided by 3 (3 test scores are taken). I will take the sum of "264/3" and multiply it by 0.45 (because the tests are worth 45%)

average = (sum/numlab);
return (average * lab_percent);

For the final grade, I am trying to get a letter grade from how many points I would have from "Test points, Lab points, Project points etc."

The grading criteria is

Tests 45%
Projects 20%
Final exam 25%
Labs 10%

90-100%  A
80-90%    B
70-79%    C
60-69%    D
Less than 60%  F

Here is my updated code that I have so far:

#include <iostream>
#include <iomanip>

using namespace std;

const double test_percent = 0.45;
const double lab_percent = 0.10;
const double project_percent = 0.20;
const double finalexam_percent = 0.25;

double testpoints();
double labpoints();
double projectpoints();
double finalexampoints();
double finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints);
double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

int main ()
{

    cout<<fixed<<showpoint;
    cout.precision(2);

    double testscores;
    double labscores;
    double projectscores;
    double finalexamscores;
    double finalgradescore;


    testpoints();
    labpoints();
    projectpoints();
    finalexampoints();
    finalgrade(testscores,labscores,projectscores,finalexamscores);
    printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);

    system ("PAUSE");
    return 0;
}

    double testpoints ()
    {
           double numtest;
           double testscores;
           double totaltestpoints;
           double average;
           double sum = 0;

           cout<<"How many test did you take? "<<endl;
           cin>>numtest;


           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter score for test #"<<i<<endl;
               cin>>testscores;

               sum+=testscores;   

           }

           average = (sum/numtest);
           totaltestpoints = average * test_percent;
           return (average * test_percent);

    }

    double labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;

           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;


           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;

               sum+=labscores;
           }

           average = (sum/numlab);
           return (average * lab_percent);

    }

    double projectpoints ()
    {
           double numproject;
           double projectscores;
           double average;
           double sum = 0;

           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;


           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter score for project #"<<i<<endl;
               cin>>projectscores;

               sum+=projectscores;
           }

           average = (sum/numproject);
           return (average * project_percent);

    }

         double finalexampoints ()
    {
           double numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;

           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;


           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for Final Exam #"<<i<<endl;
               cin>>finalexamscores;

               sum+=finalexamscores;
           }

           average = (sum/numfinalexam);
           return (average * finalexam_percent);

    }

           double finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
    {

    }
           double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
    {
           double totalpoints;

           totalpoints = (testpoints + labpoints + projectpoints + finalexampoints);


           cout<<"Test points: "<<testpoints<<endl;
           cout<<"Lab points: "<<labpoints<<endl;
           cout<<"Project points: "<<projectpoints<<endl;
           cout<<"Final Exam points: "<<finalexampoints<<endl;
           cout<<"Total points: "<<totalpoints<<endl;
           cout<<"Final Grade: "<<finalgrade<<endl;

    }

double testscores;
testpoints();
finalgrade(testscores);

I've taken three lines of code from your main() and in finalgrade() I've eliminated all the parameters save one for simplicities sake.

The result of testpoints() should be assigned to testscores so that testscores has a value when sent to finalgrade(). So do somthing like this:

double testscores;
testscores = testpoints();
finalgrade(testscores);

and repeat for all the other variables passed to finalgrade.

Within testpoints() replace this variable:

double testscores;

with this:

double points;

so you don't confuse this testscores with the one in main() as they aren't the same ones. Do the same in the other functions as well.

I should think finalgrade would return type char not type double. I'd also change this:

double finalgradescore;

to this:

char finalgrade;

Alright, now it's atleast working, it's now about functionality...

The main problem I see is scope, as it is your functions return a value but nothing visible recieves that value... Lerner has said it basically

testscores = testpoints();

this way the return value in testpoints() gets sent into testscores... In my previous example (the post before this) it show ret_value recieving the return value from the function. printresults() doesn't have a return value, doesn't need one, that is the 1 function you can change to void.

I should think finalgrade would return type char not type double. I'd also change this:

double finalgradescore;

to this:

char finalgrade;

Only problem is finalgrade() hasn't been wrote at all & thus has no return value currently. But you are otherwise correct finalgrade should work out the final grade & return a char of the letter of the final grade.

char finalgradescore;
finalgradescore = finalgrade(testscores,labscores,projectscores,finalexamscores);
printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);

Everything looks beautiful now. I'm getting the correct scores for my program now. That is super great. Now, I just need to figure out how to get the Finalgrade as a letter grade.

Would I need a switch statement somewhere? If so, where would I put it in the code? If I do this, how do I return the "letter" into the final grade?

Here is my updated code:

#include <iostream>
#include <iomanip>

using namespace std;

const double test_percent = 0.45;
const double lab_percent = 0.10;
const double project_percent = 0.20;
const double finalexam_percent = 0.25;

double testpoints();
double labpoints();
double projectpoints();
double finalexampoints();
char finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints);
double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

int main ()
{

    cout<<fixed<<showpoint;
    cout.precision(2);

    double testscores;
    double labscores;
    double projectscores;
    double finalexamscores;
    double finalgradescore;


    testscores = testpoints();
    labscores = labpoints();
    projectscores = projectpoints();
    finalexamscores = finalexampoints();
    finalgrade(testscores,labscores,projectscores,finalexamscores);
    printresults(testscores,labscores,finalexamscores,projectscores,finalgradescore);

    system ("PAUSE");
    return 0;
}

    double testpoints ()
    {
           double numtest;
           double testscores;
           double totaltestpoints;
           double average;
           double sum = 0;

           cout<<"How many test did you take? "<<endl;
           cin>>numtest;


           for (int i=1; i<=numtest; i++)
           {
               cout<<"Enter score for test #"<<i<<endl;
               cin>>testscores;

               sum+=testscores;   

           }

           average = (sum/numtest);
           totaltestpoints = average * test_percent;
           return (average * test_percent);

    }

    double labpoints ()
    {
           double numlab;
           double labscores;
           double average;
           double sum = 0;

           cout<<"How many labs did you take? "<<endl;
           cin>>numlab;


           for (int i=1; i<=numlab; i++)
           {
               cout<<"Enter score for lab #"<<i<<endl;
               cin>>labscores;

               sum+=labscores;
           }

           average = (sum/numlab);
           return (average * lab_percent);

    }

    double projectpoints ()
    {
           double numproject;
           double projectscores;
           double average;
           double sum = 0;

           cout<<"How many projects did you take? "<<endl;
           cin>>numproject;


           for (int i=1; i<=numproject; i++)
           {
               cout<<"Enter score for project #"<<i<<endl;
               cin>>projectscores;

               sum+=projectscores;
           }

           average = (sum/numproject);
           return (average * project_percent);

    }

         double finalexampoints ()
    {
           double numfinalexam;
           double finalexamscores;
           double average;
           double sum = 0;

           cout<<"How many final exams did you take? "<<endl;
           cin>>numfinalexam;


           for (int i=1; i<=numfinalexam; i++)
           {
               cout<<"Enter score for Final Exam #"<<i<<endl;
               cin>>finalexamscores;

               sum+=finalexamscores;
           }

           average = (sum/numfinalexam);
           return (average * finalexam_percent);

    }

           char finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
    {

    }
           double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade)
    {
           double totalpoints;

           totalpoints = (testpoints + labpoints + projectpoints + finalexampoints);


           cout<<"Test points: "<<testpoints<<"%"<<endl;
           cout<<"Lab points: "<<labpoints<<"%"<<endl;
           cout<<"Project points: "<<projectpoints<<"%"<<endl;
           cout<<"Final Exam points: "<<finalexampoints<<"%"<<endl;
           cout<<"Total points: "<<totalpoints<<"%"<<endl;
           cout<<"Final Grade: "<<finalgrade<<"%"<<endl;

    }

Everything looks beautiful now. I'm getting the correct scores for my program now. That is super great. Now, I just need to figure out how to get the Finalgrade as a letter grade.

Would I need a switch statement somewhere? If so, where would I put it in the code? If I do this, how do I return the "letter" into the final grade?

There are often multiple ways to achieve the same result, that is you can use an if/else if/else structure or switch, personally I prefer the former over the latter but that is simply my preference. Conditional statements can often achieve what you want for example say you make up your final percentage then use conditional statements, for simplicity in this case we'll pretend final percent (overall) is called finalp.

char finalgradechar;

if (finalp < 60 && finalp >0)
finalgradechar = 'e';

else if (finalp >= 60 && finalp < 70)
finalgradechar = 'd';

else if (finalp >= 70 && finalp < 80)
finalgradechar = 'c';

& so on.

As said earlier multiple way to achieve the same results, you could pass a char through to the function & alter that after each if. Or perhaps instead of "finalgradechar = 'e';" you could have "return 'e';" which would then return the grade letter, in fact that is probably the lightest option.

char finalgradescore;
finalgradescore = finalgrade(testscores,labscores,projectscores,finalexamscores);

then have something like


if (finalp < 60 && finalp >0)
return 'e';

else if (finalp >= 60 && finalp < 70)
return 'd';

else if (finalp >= 70 && finalp < 80)
return 'c';

What would happen then is "finalgradescore" would end up with whatever character the function returns from the if/else if/else statements.

double printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,double& finalgrade);

would also need to be changed to

void printresults(double testpoints,double labpoints,double finalexampoints,double projectpoints,char& finalgrade);
as would the prototype & the actual functions which recieve finalgrade.

Where to put the code? I've been assuming right here

char finalgrade(double& testpoints, double& labpoints,double& finalexampoints,double& projectpoints)
{

}

the 1 empty function in your program.

Mission is complete! Everything works perfectly. Thank you guys soo much. I appreciate it! =)

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.