Can someone please copy/paste the following source and look at the error message? I am receiving too few arguements to function error.
Please help!


//preprocessor directive
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

//global variables/constants, function prototypes
void headerfn(); // void fn without parameters
void namefn(string fname, string lname); // void fn with parameters
void inputfn(int prog1, int prog2, int prog3, int test1, int test2, int test3);
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3);
void outputfn(string fname, string lname, int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade);

int main(){
system("color f0");
headerfn(); // functional call
string fname, lname; //declaring variables
namefn(fname, lname); //function call

int prog1, prog2, prog3, test1, test2, test3; // declaring variables
inputfn(prog1, prog2, prog3, test1, test2, test3); // function call

float progavg, testavg, courseavg; // declaring variables
int totalpts;
char grade;
resultsfn(totalpts, progavg, testavg, courseavg, grade); // functional call

outputfn(fname, lname, totalpts, progavg, testavg, courseavg, grade);

system("pause");
return 0;
}

// void fn without parameters
void headerfn(){
cout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;
cout<<"************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* IT Business Applications with C++ *"<<endl;
cout<<"* Programmer: John Doe *"<<endl;
cout<<"* Date: November 9, 2009 *"<<endl;
cout<<"* *"<<endl;
cout<<"* This program uses functions to read student *"<<endl;
cout<<"* information from keyboard and outputs *"<<endl;
cout<<"* the results to the monitor and a text file *"<<endl;
cout<<"* *"<<endl;
cout<<"************************************************************"<<endl;
}// end of headerfn

//******************************************************************************
//void fn with parameters
void namefn(string fname, string lname){
cout<<"Please enter your first and last name: ";
cin>>fname>>lname;
}// end of namefn

//******************************************************************************
//void fn with reference parameters
void inputfn(int prog1, int prog2, int prog3, int test1, int test2, int test3){
cout<<"Please enter the first program score: ";
cin>>prog1;
cout<<"Please enter the second program score: ";
cin>>prog2;
cout<<"Please enter the third program score: ";
cin>>prog3;
cout<<"Please enter the first test score: ";
cin>>test1;
cout<<"Please enter the second test score: ";
cin>>test2;
cout<<"Please enter the third test score: ";
cin>>test3;
}//end of inputfn

//******************************************************************************
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3){
totalpts = (prog1+prog2+prog3+test1+test2+test3);
progavg = (prog1+prog2+prog3)/3.0;
testavg = (test1+test2+test3)/3.0;
courseavg = (progavg+testavg)/2.0;

if (courseavg >=90 )grade='A';
else if (courseavg >=80 )grade='B';
else if (courseavg >=70 )grade='C';
else grade='F';
} //end of resultsfn

//******************************************************************************
void outputfn(string fname, string lname, int totalpts, float, progavg, float testavg, float courseavg, char grade){
cout<<"12345678901234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"================================================================================"<<endl;
cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<fixed<<showpoint<<setprecision(2);
cout<<left<<setw(20)<<first+" "+last<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;

cout<<"======================================================================"<<endl;

fout<<"01234567890123456789012345678901234567890123456789123456789"<<endl;
fout<<"***********************************************************"<<endl;
fout<<"* IT210 Business Applications with C++ *"<<endl;
fout<<"* Programmer: John Doe *"<<endl;
fout<<"* Date: October 26, 2009 *"<<endl;
fout<<"* *"<<endl;
fout<<"* Program Assignment 2: Student Grades II *"<<endl;
fout<<"* *"<<endl;
fout<<"* This program reads student information from *"<<endl;
fout<<"* an input text file and outputs the result *"<<endl;
fout<<"* to the monitor as well as to a text file *"<<endl;
fout<<"* *"<<endl;
fout<<"***********************************************************"<<endl;
fout<<endl;
fout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
fout<<"======================================================================"<<endl;
fout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
fout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
fout<<"----------------------------------------------------------------------"<<endl;

fout<<"======================================================================"<<endl;
fout.close();

} //end of outputfn

Why are you calling resultsfn with only 5 parameters when it takes 11 in your prototype and definition? It will not assume defaults for those. Often what the compiler says, goes.

First: USE CODE TAGS

Second: you don't not have to declare the variable name in definitions e.g. void resultsfn(int& A); is the same as void resultsfn(int&); .
This often makes code clearer

Three: Dont use

system("pause");

.

Four: You use references BUT the fail to use references in namefn for example. namefn is equivilent to reading two names from the keyboard and discarding them.

Five: You declare resultsfn with SO many variables I can't be bothered to count them. BUT you call it with only 5. That is an error. You need to call it with exactly the number of variables that you declared it with unless you use default values. You are missing all the integers from the end.

Six: Don't use using namespace std; . What is the point of a namespace if you just ignore it. The namespace is to avoid mistypes with short names e.g. cout, ios, string, and others.

Seven: Don't use variable names that a single character away from another variable name. E.g Dont use fout in function outputfn since you have cout. That is asking for trouble .

Eight If you want to writ to a file then open the file first e.g. std::ofstream fileOut(fname.c_str()); Nine: Correct all the warnings

Ten You have an a comma between float and progavg in function outputfn.

Eleven: declaration and implementation signature of outputfn are not the same.

Think that is about it. After that you will HAVE to debug it. that means going through function by function and checking that it does what you expect. That will mean writing about the same amount of lines of code again to test each function. That is 100% part of writing software and is 99% unavoidable.

Why are you calling resultsfn with only 5 parameters when it takes 11 in your prototype and definition? It will not assume defaults for those. Often what the compiler says, goes.

good catch! Thanks.. I will continue down the line and will repost if I come across any more errors. :)

Thanks so much for looking into it! I am a beginner and was missing some obvious points. I'll check back on some of these. I am using namespace along with #include <fstream> in order to use both cout and fout as that is part of the assignment.

I am using namespace along with #include <fstream> in order to use both cout and fout as that is part of the assignment.

Well DONT use using namespace std; You can write it like this:

std::ofstream File("Output.txt")
File<<"This is to the file"<<std::endl;
std::cout<<"Written line to the output file"<<std::endl;

Namespaces are there to avoid global name pollution. You have no idea how many names are in namespace std, it is lots. So don't pollute you program with them, because when you get it wrong the compile error messages are simple incomprehensible.

Namespaces are important, but for the sake of a school assignment you could probably put using std::cout; and using std::endl; instead. Then you'd have to specify for the std::ofstream , etc. But I do concede to your point Stu and agree that good habits are important at any stage of the game.

commented: good comment on using (well you agreed with me :) +2

I agree with Jonsa's point you can put using std::cout; etc, although it is important to remember that they can be put within a scope, e.g. in a function and not the global scope.

C++ is a language that seems to deplore sloppy practice, so in almost all cases always default to more rigor. E.g. if you always define a copy constructor and assignment operator and destructor, your are going to be ok, or if you always make the destructor virtual if you have a virtual function. These are all not necessary but get one of those wrong will cost you a lot of time in debugging.

So if you are beginning don't take short cuts, it will not save time

Okay guys, I am not getting any debugging error BUT it is not displaying the names and scores correctly. I am thinking there is issue with manipulators but I can't quite make it out. Any help would be much appreciated!!

//IT210 Business Applications with C++
//Programmer: John Doe
//Date:       November 9, 2009
//Assignment 3: Functions

//preprocessor directive
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

//global variables/constants, function prototypes
void headerfn(); // void fn without parameters
void namefn(string fname, string lname); // void fn with parameters
void inputfn(int prog1, int prog2, int prog3, int test1, int test2, int test3);
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3);
void outputfn(string fname, string lname, int totalpts, float progavg, float testavg, float courseavg, char grade);

int main(){
    system("color f0");
    headerfn(); // functional call
    string fname, lname; //declaring variables
    namefn(fname, lname); //function call
    
    int prog1, prog2, prog3, test1, test2, test3; // declaring variables
    inputfn(prog1, prog2, prog3, test1, test2, test3); // function call
    
    float progavg, testavg, courseavg; // declaring variables
    int totalpts;
    char grade;
    
    resultsfn(totalpts,progavg,testavg,courseavg,grade,prog1,prog2,prog3,test1,test2,test3);
    
    outputfn(fname, lname, totalpts, progavg, testavg, courseavg, grade);
    
    system("pause");
    return 0;
}

// void fn without parameters
void headerfn(){
     cout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;
     cout<<"************************************************************"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"*          IT Business Applications with C++               *"<<endl;
     cout<<"*          Programmer: John Doe                              *"<<endl;
     cout<<"*          Date: November 9, 2009                          *"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"*          This program uses functions to read student     *"<<endl;
     cout<<"*          information from keyboard and outputs           *"<<endl;
     cout<<"*          the results to the monitor and a text file      *"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"************************************************************"<<endl;
     cout<<endl;
     cout<<"Welcome to the IT 210 Grade Calculator!\n"<<endl;
     }// end of headerfn

//******************************************************************************
//void fn with parameters
void namefn(string fname, string lname){
     cout<<"Please enter your first and last name: ";
     cin>>fname>>lname;
     }// end of namefn

//******************************************************************************
//void fn with reference parameters
void inputfn(int prog1, int prog2, int prog3, int test1, int test2, int test3){
     cout<<"Please enter the first program score: ";
     cin>>prog1;
     cout<<"Please enter the second program score: ";
     cin>>prog2;
     cout<<"Please enter the third program score: ";
     cin>>prog3;
     cout<<"Please enter the first test score: ";
     cin>>test1;
     cout<<"Please enter the second test score: ";
     cin>>test2;
     cout<<"Please enter the third test score: ";
     cin>>test3;
     }//end of inputfn

//******************************************************************************
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3){
    totalpts = (prog1+prog2+prog3+test1+test2+test3);
    progavg = (prog1+prog2+prog3)/3.0;
    testavg = (test1+test2+test3)/3.0;
    courseavg = (progavg+testavg)/2.0;
    
    if (courseavg >=90 )grade='A';
    else if (courseavg >=80 )grade='B';
    else if (courseavg >=70 )grade='C';
    else grade='F';
} //end of resultsfn    

//******************************************************************************
void outputfn(string fname, string lname, int totalpts, float progavg, float testavg, float courseavg, char grade){
    ofstream fout;
    fout.open("output.txt");
    
    if(!fout){
              cout<<"Output Failure"<<endl;
              system("pause");
              //return 0;
              } //end of error check
    cout<<"12345678901234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
    cout<<"================================================================================"<<endl;          
    cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
    cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
    //cout<<fname+" "+lname<<progavg<<testavg<<courseavg<<grade<<endl;
    cout<<"======================================================================"<<endl;
    
    fout<<"01234567890123456789012345678901234567890123456789123456789"<<endl;
    fout<<"***********************************************************"<<endl;
    fout<<"*         IT210 Business Applications with C++            *"<<endl;
    fout<<"*         Programmer: John Doe                                *"<<endl;
    fout<<"*         Date: October 26, 2009                          *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"*         Program Assignment 2: Student Grades II         *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"*         This program reads student information from     *"<<endl;
    fout<<"*         an input text file and outputs the result       *"<<endl;
    fout<<"*         to the monitor as well as to a text file        *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"***********************************************************"<<endl;
    fout<<endl;
    fout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
    fout<<"======================================================================"<<endl;          
    fout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
    fout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
    fout<<"----------------------------------------------------------------------"<<endl;  
    
    fout<<"======================================================================"<<endl;
    fout<<fixed<<showpoint<<setprecision(2);
    fout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
    fout<<"======================================================================"<<endl;
    fout.close(); 
    
} //end of outputfn

You need to change all the variables in inputfn to references, otherwise you'll just have whatever garbage is in those locations after they are initialized. EDIT: file IO seems to be ok.

Your code really overwhelmed me at first, but then I got used to it...and I did figure it out. :)

Your error is as follows:
- You forgot to use #include<string>! (yep, a dumb error, I make them all the time..and I am sure everyone else does too :))

Great code btw, I like how you changed the color.

Edit: Oh, and one more thing. Some of your functions are not initializing the variables correctly. You need to add the ampersand(&) to most of your function variables.

For your convenience, here is the code up and running:

//IT210 Business Applications with C++
//Programmer: John Doe
//Date:       November 9, 2009
//Assignment 3: Functions
 
//preprocessor directive
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
using namespace std;
 
//global variables/constants, function prototypes
void headerfn(); // void fn without parameters
void namefn(string fname, string lname); // void fn with parameters
void inputfn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3);
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3);
void outputfn(string fname, string lname, int totalpts, float progavg, float testavg, float courseavg, char grade);
 
int main(){
    system("color f0");
    headerfn(); // functional call
    string fname, lname; //declaring variables
    namefn(fname, lname); //function call
 
    int prog1, prog2, prog3, test1, test2, test3; // declaring variables
    inputfn(prog1, prog2, prog3, test1, test2, test3); // function call
 
    float progavg, testavg, courseavg; // declaring variables
    int totalpts;
    char grade;
 
    resultsfn(totalpts,progavg,testavg,courseavg,grade,prog1,prog2,prog3,test1,test2,test3);
 
    outputfn(fname, lname, totalpts, progavg, testavg, courseavg, grade);
 
    system("pause");
    return 0;
}
 
// void fn without parameters
void headerfn(){
     cout<<"012345678901234567890123456789012345678901234567890123456789"<<endl;
     cout<<"************************************************************"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"*          IT Business Applications with C++               *"<<endl;
     cout<<"*          Programmer: John Doe                            *"<<endl;
     cout<<"*          Date: November 9, 2009                          *"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"*          This program uses functions to read student     *"<<endl;
     cout<<"*          information from keyboard and outputs           *"<<endl;
     cout<<"*          the results to the monitor and a text file      *"<<endl;
     cout<<"*                                                          *"<<endl;
     cout<<"************************************************************"<<endl;
     cout<<endl;
     cout<<"Welcome to the IT 210 Grade Calculator!\n"<<endl;
     }// end of headerfn
 
//******************************************************************************
//void fn with parameters
void namefn(string fname, string lname){
     cout<<"Please enter your first and last name: ";
     cin>>fname>>lname;
     }// end of namefn
 
//******************************************************************************
//void fn with reference parameters
void inputfn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){
     cout<<"Please enter the first program score: ";
     cin>>prog1;
     cout<<"Please enter the second program score: ";
     cin>>prog2;
     cout<<"Please enter the third program score: ";
     cin>>prog3;
     cout<<"Please enter the first test score: ";
     cin>>test1;
     cout<<"Please enter the second test score: ";
     cin>>test2;
     cout<<"Please enter the third test score: ";
     cin>>test3;
     }//end of inputfn
 
//******************************************************************************
void resultsfn(int &totalpts, float &progavg, float &testavg, float &courseavg, char &grade, int prog1, int prog2, int prog3, int test1, int test2, int test3){
    totalpts = (prog1+prog2+prog3+test1+test2+test3);
    progavg = (prog1+prog2+prog3)/3.0;
    testavg = (test1+test2+test3)/3.0;
    courseavg = (progavg+testavg)/2.0;
 
    if (courseavg >=90 )grade='A';
    else if (courseavg >=80 )grade='B';
    else if (courseavg >=70 )grade='C';
    else grade='F';
} //end of resultsfn    
 
//******************************************************************************
void outputfn(string fname, string lname, int totalpts, float progavg, float testavg, float courseavg, char grade){
    ofstream fout;
    fout.open("output.txt");
 
    if(!fout){
              cout<<"Output Failure"<<endl;
              system("pause");
              //return 0;
              } //end of error check
    cout<<"12345678901234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
    cout<<"================================================================================"<<endl;          
    cout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
    cout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
    cout<<"--------------------------------------------------------------------------------"<<endl;
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
    //cout<<fname+" "+lname<<progavg<<testavg<<courseavg<<grade<<endl;
    cout<<"======================================================================"<<endl;
 
    fout<<"01234567890123456789012345678901234567890123456789123456789"<<endl;
    fout<<"***********************************************************"<<endl;
    fout<<"*         IT210 Business Applications with C++            *"<<endl;
    fout<<"*         Programmer: John Doe                                *"<<endl;
    fout<<"*         Date: October 26, 2009                          *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"*         Program Assignment 2: Student Grades II         *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"*         This program reads student information from     *"<<endl;
    fout<<"*         an input text file and outputs the result       *"<<endl;
    fout<<"*         to the monitor as well as to a text file        *"<<endl;
    fout<<"*                                                         *"<<endl;
    fout<<"***********************************************************"<<endl;
    fout<<endl;
    fout<<"1234567890123456789012345678901234567890123456789012345678901234567890"<<endl;
    fout<<"======================================================================"<<endl;          
    fout<<left<<setw(20)<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
    fout<<right<<setw(26)<<"Points"<<setw(11)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;
    fout<<"----------------------------------------------------------------------"<<endl;  
 
    fout<<"======================================================================"<<endl;
    fout<<fixed<<showpoint<<setprecision(2);
    fout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpts<<setw(10)<<progavg<<setw(10)<<testavg<<setw(10)<<courseavg<<setw(10)<<grade<<endl;
    fout<<"======================================================================"<<endl;
    fout.close(); 
 
} //end of outputfn

Okay. Thanks so much for looking into it. I am going to try and clean them up and see how they work out.

Thanks to everyone for helping me figure issues out with my code. I really apologize it took me this long to appreciate for all of your assistance. I had assignment due and the test happened to be on the same day, so I got tied up trying to figure out the problems and did not get chance to come back here to appreicate everyone's assistance throughout the process. Thanks again and I hope that after learning few things, I will be able to assist others in need as well. :)

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.