invalid operands of types int and float to binary operator <<

closed account (iTMjLyTq)
Okay, so the program works until I add the last part on and then I get this error message: invalid operands of types int and float to binary operator <<


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//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)
int scorefn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3); //value w/parameters
int gradesfn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3); //value w/parameters

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
    
    int score;
    score= scorefn(prog1, prog2, prog3, test1, test2, test3);//value returning function call
    
    int grades;
    grades=gradesfn(prog1, prog2, prog3, test1, test2, test3);
    float progavg, testavg, courseavg;
    char grade;
     //value returning function call
    
    

 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 Parameters
int scorefn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){
int score;
if (score>100 || score<0){cout<<"Invalid! Please enter another score: ";
cin>>score;}
}

//********************************************************************************
//Value Returning Function with Parameters
int gradesfn(int &prog1, int &prog2, int &prog3, int &test1, int &test2, int &test3){
int totalpoints;
string fname;
string lname;
float progavg=0.00;
float testavg=0.00;
float courseavg=0.00;

cout<<endl<<"123456789012345678901234567890123456789012345678901234567890"<<endl;
cout<<"============================================================"<<endl;
cout<<setfill(' ')<<"Student Name"<<setw(10)<<"Total"<<setw(10)<<"Program"<<setw(10)<<"Test"<<setw(10)<<"Course"<<setw(10)<<"Grade"<<endl;
cout<<setw(23)<<"Points"<<setw(10)<<"Average"<<setw(10)<<"Average"<<setw(10)<<"Average"<<endl;

//Calculations
totalpoints=prog1+prog2+prog3+test1+test2+test3;
progavg=(prog1+prog2+prog3)/3.0;
testavg=(test1+test2+test3)/3.0;
courseavg=(progavg+testavg)/2.0;

cout<<fixed;
cout<<setprecision(2);
cout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpoints<<setw(10)<<progavg<<setw(10<<testavg<<sewtw(10<<grade;
}




It works until I put cout<<left<<setw(20)<<fname+" "+lname<<setw(10)<<totalpoints<<setw(10)<<progavg<<setw(10<<testavg<<sewtw(10<<grade;. What do I need to change?????
closed account (iTMjLyTq)
Oh my God, nevermind, now I see all the typos I made. Haha, oops.
closed account (iTMjLyTq)
But I have a new question: how do I reference the first name and last name from the second void functino and get them to show up in the last function?
You have to pass them as parameters to the function.

BTW, just a word of advice regarding your coding style: the spacebar is your friend.
Topic archived. No new replies allowed.