functions.....so confused

closed account (iTMjLyTq)
Okay, so I'm writing this program that asks for 6 grades and calculates averages and stuff. I need to check to ensure that each input score is not less than 0 or greater than 100, and prompt the user to reenter their score if they first entered a score that was not in the specified range. I have to use a value reurning function with parameters to do so.

This is what I have so far and it is not working!

//Preprocessor Directives
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;

//Global variables/constants, function prototypes
void headerfn();//void function with no parameters
void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3);//void w/ parameters (reference)
float inputfn(string input);

int main(){
    system("color f0");
    headerfn();//void function call
    
    string fname, lname;
    int prog1, prog2, prog3, test1, test2, test3;
    inputfn(fname, lname, prog1, prog2, prog3, test1, test2, test3);//void function call
    
    float input;
    input=inputfn(fname, lname, prog1, prog2, prog3, test1, test2, test3);

 system("pause");
    return 0;
}//end of main

//************************************************************
//Void Function Without Parameters
void headerfn(){
     cout<<"123456789012345678901234567890123456789012345678901234567890"<<endl;
     cout<<setw(60)<<setfill('*')<<"*"<<endl;
     cout<<"*        IT 210 Business Applications with C++             *\n";
     cout<<"*        Programmer: Kate Hamby                            *\n";
     cout<<"*        Date: November 02, 2009                           *\n";
     cout<<"*                                                          *\n";
     cout<<"*        Program Assignment 3: Student Grades III          *\n";
     cout<<"*                                                          *\n";
     cout<<"*        This program uses functions to read student       *\n";
     cout<<"*        information from the keyboard and outputs         *\n";
     cout<<"*        the results to the monitor and a text file.       *\n";
     cout<<setw(60)<<setfill('*')<<"*"<<endl;
     }//end of headerfn




//************************************************************
//Void Function With Parameters
void inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){

    
     cout<<"Please enter your first and last name: ";
     cin>>fname>>lname;         
     cout<<endl<<"Please enter the first program score: ";
     cin>>prog1;
     cout<<endl<<"Please enter the second program score: ";
     cin>>prog2;
     cout<<endl<<"Please enter the third program score: ";
     cin>>prog3;
     cout<<endl<<"Please enter the first test score: ";
     cin>>test1;
     cout<<endl<<"Please enter the second test score: ";
     cin>>test2;
     cout<<endl<<"Please enter the third test score: ";
     cin>>test3; 
 
 


//************************************************************
//Value Returning Function With Parameter
float inputfn(string &fname, string &lname, int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){
float input;
if (input<0) cout<<"This score is invalid! PLease enter a score between 0-100: ";
else if (input>100) cout<<"This score is invalid! PLease enter a score between 0-100: ";

return input;
}



I need help. Badly.
a: use the code tags please
b: in order to use system("color f0") you must include #include <stdlib.h>
c: if inputfn is void it can't have a return value
input=inputfn(fname, lname, prog1, prog2, prog3, test1, test2, test3);
d: I beleive you have to call functions before main

These are ones I found

also using system is not a wise idea, see:http://www.cplusplus.com/forum/articles/11153/
Last edited on
Also, using cin to read std::strings is generally not a good idea; use std::getline(cin, string) instead. I don't think this even compiles as you are missing at least one end brace and you have inputfn() being overloaded on the return type.

Fix a couple of these things, repost with code tags/the compiler errors please.
Topic archived. No new replies allowed.