error C2065: 'std_dev' : undeclared identifier

i am having this problem from yesterday can anyone tell me how to correct the error pls
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
106
107
108
109
110
111
112
113
114
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
#include<cmath>
using namespace std;
int studentdetails_mean();
double standard_deviation();
void barchart();

int main(){
	int number_stud[5],sum=0;
	double exam_marks[5],mean=0;
	string student_name;
	ifstream infile; // input file
	ofstream outfile; //output file
	infile.open("input.txt"); 
	outfile.open("output.txt");
	
	if(!outfile){  //if cannot open the file
		cout<<"Cannot open file."<<endl;
		return 1;
	}

	string data;

	while(!infile.eof()){
		getline(infile,data);
		cout<<data<<endl;  //output to terminal window
		}
	studentdetails_mean(mean);
	standard_deviation(std_dev);
	barchart();
	infile.close();
	outfile.close();

	system("pause");
	return 0;
}

int studentdetails_mean(int mean){
	ofstream outfile;
	outfile.open("output.txt");
	string student_name;
	int exam_marks[5],sum=0;
	for(int x=0;x<5;x++){
			cout<<"Please enter the student name: ";
			cin>>student_name;
			cout<<"Please enter the examination marks: ";
			cin>>exam_marks[x];
			sum=sum+exam_marks[x];
	}
	mean=sum/5;
	outfile<<"The mean is "<<mean<<endl;
	outfile.close();
	return mean;
}

double standard_deviation(double std_dev){
	ofstream outfile;
	outfile.open("output.txt");
	int exam_marks[5],students=5,mean,sum=0;
	double sox_m,s=0;
	int nminus=4;
	for(int ii=0;ii<students;ii++){
		mean;
		s=s+((exam_marks[ii]-mean)*(exam_marks[ii]-mean));
	}
	std_dev=sqrt(s/nminus);
	cout<<"The standard deviation is: "<<std_dev<<endl;
	outfile<<"The standard deviation is: "<<std_dev<<endl;
	outfile.close();
	return std_dev;
}

void barchart(){
	ofstream outfile;
	outfile.open("output.txt");
	int G_A=0,G_B=0,G_C=0,G_D=0,G_F=0,exam_marks[5];
	for(int x=0;x<5;x++){
	if(exam_marks[x]<=39.9){
		cout<<"Grade F"<<setw(15)<<endl;  
		outfile<<"Grade F";
		cout<<"*"<<endl;
		outfile<<"*"<<endl;
		G_F++;
	}else if(exam_marks[x]<=49.9){
		cout<<"Grade D"<<setw(15)<<endl;
		outfile<<"Grade D";
		cout<<"*"<<endl;
		outfile<<"*"<<endl;
		G_D++;
	}else if(exam_marks[x]<=69.9){
		cout<<"Grade C"<<setw(15)<<endl;
		outfile<<"Grade C";
		cout<<"*"<<endl;
		outfile<<"*"<<endl;
		G_C++;
	}else if(exam_marks[x]<=79.9){
		cout<<"Grade B"<<setw(15)<<endl;
		outfile<<"Grade B";
		cout<<"*"<<endl;
		outfile<<"*"<<endl;
		G_B++;
	}else if(exam_marks[x]<=100){
		cout<<"Grade A"<<setw(15)<<endl;
		outfile<<"Grade A";
		cout<<"*"<<endl;
		outfile<<"*"<<endl;
		G_A++;
	}
	outfile.close();
	}
}


this is the error its showing up now:
error C2660: 'studentdetails_mean' : function does not take 1 arguments
error C2065: 'std_dev' : undeclared identifier
Last edited on
As your compiler says, on line 32 you have an undeclared identifier std_dev. Define it before you use it.

The fact that your standard_deviation function requires input is questionable, since you don't actually use that input.

You do realize you're truncating your output file at the beginning of every function?
how to define it?...
The same way you would define any other variable.

double std_dev ;
i should define it in the main or in the function header?
Topic archived. No new replies allowed.