I have to make a program in which a teacher is inputing the scores of each student in a file.There are several marks:
A 90-100
B 80-89
C 70-79
D 60-69
F 0-59
The teacher should be able to see the number of students who have passed, the avarege score of the whole class and the number of students in each "mark" (the number with A,B,C,D,F)
here is my code, i hope that you will find a way to help me
#include <iostream>
#include <fstream>
usingnamespace std;
struct Student
{
char first_name[20];
char secound_name[20];
char last_name[20];
double points;
};
int main()
{
int A;
int B;
int C;
int D;
int F;
int p;
ofstream file;
file.open("file.txt", ios::out);
Student students[35];
int n, i;
cout << "Number students: ";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "Name: ";
cin >> students[i].first_name;
cout << "Secound: ";
cin >> students[i].secound_name;
cout << "Last: ";
cin >> students[i].last_name;
cout << "points: ";
cin >> students[i].points;
file << struct.students.first_name;
}
if (p < 60)
F++;
else
{
if (60 <= p && 70 > p)
D++;
elseif (70 <= p && 80 > p)
C++;
elseif (80 <= p && 90 > p)
B++;
elseif (90 <= p && 100 >= p)
A++;
} // end else
} // end if
cout << "# of students in group is " << n << ;
cout << "# of students with A degree is " << A << ;
cout << "# of students with B degree is " << B <<;
cout << "# of students with C degree is " << C << ;
cout << "# of students with D degree is " << D <<;
cout << "# of students with F degree is " << F << ;
int passed;
passed = (A + B + C + D);
int avg;
avg = (p / n);
file.close();
return 0;
system("pause");
}
I was just trying to get something going, if i manage to save the first name in the file i should be able to save everything from the structure. I am trying to understand the basis of the way i should create the program.
The main problem is that my code is not working. (unfunny joke)
The problem is that the code is having a lot of errors I don't know how to deal with, some syntaxx erros that I think that should not be there but maybe i am not doing something right.
Also there isn't any data saved in the text file, I have opening and closing files for saving information in other programs, but it;s not working. :/
The problem is that the code is having a lot of errors I don't know how to deal with, some syntaxx erros that I think that should not be there but maybe i am not doing something right.
Yes your program has syntax errors that your compiler should be telling you about. Perhaps if you posted your compiler error messages someone can help you understand the messages.
Looking at the compiler output from the embedded compiler (press the gear button) the first thing you need to look into is mismatched or misplaced braces.
At global scope: ///////// Big big clue here.
72:5: error: 'cout' does not name a type
jib, that it is the actual code (the one I had put in the first post). I cannot understand what you are wanting from me to post :/ aren't the screenshots visable enough? i am able to see everything clearly when i click on the image after I open the link
#include <iostream>
#include <fstream>
usingnamespace std;
struct Student
{
char first_name[20];
char secound_name[20];
char last_name[20];
double points;
};
int main()
{
int A;
int B;
int C;
int D;
int F;
int p;
ofstream file;
file.open("file.txt", ios::out);
Student students[35];
int n, i;
cout << "Number students: ";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "Name: ";
cin >> students[i].first_name;
cout << "Secound: ";
cin >> students[i].secound_name;
cout << "Last: ";
cin >> students[i].last_name;
cout << "points: ";
cin >> students[i].points;
file << struct.students.first_name;
}
if (p < 60)
F++;
else
{
if (60 <= p && 70 > p)
D++;
elseif (70 <= p && 80 > p)
C++;
elseif (80 <= p && 90 > p)
B++;
elseif (90 <= p && 100 >= p)
A++;
} // end else
cout << "# of students in group is " << n <<endl;
cout << "# of students with A degree is " << A <<endl;
cout << "# of students with B degree is " << B <<endl;
cout << "# of students with C degree is " << C <<endl;
cout << "# of students with D degree is " << D <<endl;
cout << "# of students with F degree is " << F <<endl;
} // end if
int passed(0);
passed = (A + B + C + D);
int avg(0);
avg = (p / n);
file.close();
return 0;
system("pause");
}
I see that now most of them are in the last part of the code, but i still have no idea how to sort that thing in line 42. Now i will try to repair the bottom part.
I suppose that this is what you want, here are the errors from the last screenshot
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(42): error C2332: 'struct' : missing tag name
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(42): error C2226: syntax error : unexpected type 'main::<unnamed-tag>'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C2374: 'passed' : redefinition; multiple initialization
1> c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(86) : see declaration of 'passed'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C2065: 'A' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C2065: 'B' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C2065: 'C' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(87): error C2065: 'D' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(89): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(89): error C2374: 'avg' : redefinition; multiple initialization
1> c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(88) : see declaration of 'avg'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(89): error C2065: 'p' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(89): error C2065: 'n' : undeclared identifier
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(91): error C2143: syntax error : missing ';' before '.'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(91): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(92): error C2059: syntax error : 'return'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(93): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(93): error C2365: 'system' : redefinition; previous definition was 'function'
1> c:\program files (x86)\microsoft visual studio 12.0\vc\include\stdlib.h(560) : see declaration of 'system'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(93): error C2440: 'initializing' : cannot convert from 'const char [6]' to 'int'
1> There is no context in which this conversion is possible
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(94): error C2059: syntax error : '}'
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(94): error C2143: syntax error : missing ';' before '}'
#include <iostream>
#include <fstream>
usingnamespace std;
struct Student
{
char first_name[20];
char secound_name[20];
char last_name[20];
double points;
};
int main()
{
int A;
int B;
int C;
int D;
int F;
int p;
ofstream file;
file.open("file.txt", ios::out);
file.close();
Student students[35];
int n, i;
cout << "Number students: ";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "Name: ";
cin >> students[i].first_name;
cout << "Secound: ";
cin >> students[i].secound_name;
cout << "Last: ";
cin >> students[i].last_name;
cout << "points: ";
cin >> students[i].points;
file << struct.students.first_name;
}
if (p < 60)
{
F++;
}
else
{
if (60 <= p && 70 > p)
D++;
elseif (70 <= p && 80 > p)
C++;
elseif (80 <= p && 90 > p)
B++;
elseif (90 <= p && 100 >= p)
A++;
} // end else
cout << "# of students in group is " << n <<endl;
cout << "# of students with A degree is " << A <<endl;
cout << "# of students with B degree is " << B <<endl;
cout << "# of students with C degree is " << C <<endl;
cout << "# of students with D degree is " << D <<endl;
cout << "# of students with F degree is " << F <<endl;
int passed(0);
passed = (A + B + C + D);
int avg(0);
avg = (p / n);
system("pause");
return 0;
}
the compiler says that I am only having 2 errors both in line 43 :) how should i get rid of them and finaly save the information from the struture in the file?
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(43): error C2332: 'struct' : missing tag name
1>c:\users\todor\documents\visual studio 2013\projects\consoleapplication31\consoleapplication31\source.cpp(43): error C2226: syntax error : unexpected type 'main::<unnamed-tag>'
here are the messages
i don't think my cycles are correct, i managed to get the programm going but it doesn't count the number of students with A,B,C,D,F, no matter how many students i input, the program always outputs that the number of students with F is 1, and that there are no students with A,B,C,D
'typedef' : missing tag name
The compiler found an incomplete type definition.
The following sample generates C2332:
Do you realize that struct is a keyword. This keyword is used when creating a user defined type (like you did starting on line 5), or creating an instance of that type. Are you trying to create a new type, or an instance of some type on the line in question?
Perhaps you should review how to access class/structure member variables. http://www.cplusplus.com/doc/tutorial/structures/
Or perhaps just look at how you accessed the member variable on line 34.
#include <iostream>
#include <fstream>
usingnamespace std;
struct Student
{
char first_name[20];
char secound_name[20];
char last_name[20];
double points;
};
int main()
{
int A(0);
int B(0);
int C(0);
int D(0);
int F(0);
int p(0);
ofstream file;
file.open("file.txt", ios::out);
file.close();
Student students[35];
int n, i;
cout << "Number students: ";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "Name: ";
cin >> students[i].first_name;
cout << "Secound: ";
cin >> students[i].secound_name;
cout << "Last: ";
cin >> students[i].last_name;
cout << "points: ";
cin >> students[i].points;
file << students[i].first_name;
file << students[i].secound_name;
file << students[i].last_name;
file << students[i].points;
}
if (students[i].points < 60)
{
F++;
}
else
{
if (60 <= students[i].points && 70 > students[i].points)
D++;
elseif (70 <= students[i].points && 80 > students[i].points)
C++;
elseif (80 <= students[i].points && 90 > students[i].points)
B++;
elseif (90 <= students[i].points && 100 >= students[i].points)
A++;
} // end else
cout << "# of students in group is " << n << endl;
cout << "# of students with A degree is " << A << endl;
cout << "# of students with B degree is " << B << endl;
cout << "# of students with C degree is " << C << endl;
cout << "# of students with D degree is " << D << endl;
cout << "# of students with F degree is " << F << endl;
int passed(0);
passed = (A + B + C + D);
cout << "the number of passed students is: " <<passed<<endl;
double avg(0);
avg += students[i].points;
avg /= n;
cout << "the avarage points of the students are: " << avg << endl;
system("pause");
return 0;
}