Cant find the problem

This is a program I've written for school with the help of another student. If you run it you'll immediately see what the problem is, however I cannot. Any help and and explanation of what needs to be done, This is very frustrating.


#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<string.h>

char x[20];
int a,b,c,d,e;

using namespace std;

int main()
{
string filename, C1, C2, C3;
ifstream influte;
ofstream flute;



cout<<"Please enter filename"<<endl;
cin>>filename;
flute.open(filename.c_str());
influte.open(filename.c_str());

cout<<"Please enter number of students"<<endl;
cin>>a;
e=0,


flute<<setw(10)<<"id"<<setw(10)<<"student name "<<setw(15)<<"grade"<<endl;
for (int e=0; e<=a; e++)
{
e++;

cout<<"Enter students name"<<endl;
cin>>x;
cout<<"Enter grade"<<endl;
cin>>c;


}
cout<<setw(5)<<a<<setw(5)<<x<<setw(5)<<c<<endl;

for(int e=0; e<=a; e++)
{
influte>>C1>>C2>>C3;
cout<<setw(10)<<C1<<setw(10)<<C2<<setw(10)<<C3<<endl;

}
influte>>C1>>C2>>C3;
cout<<setw(10)<<C1<<setw(10)<<C2<<setw(10)<<C3<<endl;

influte.close();


system("pause");

return 0;

}
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
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<string.h>

char x[20];
int a,b,c,d,e;

using namespace std;

int main()
{
string filename, C1, C2, C3;
ifstream influte;
ofstream flute;



cout<<"Please enter filename"<<endl;
cin>>filename;
flute.open(filename.c_str());
influte.open(filename.c_str());

cout<<"Please enter number of students"<<endl;
cin>>a;
e=0,


flute<<setw(10)<<"id"<<setw(10)<<"student name "<<setw(15)<<"grade"<<endl;
for (int e=0; e<=a; e++)
{
e++;

cout<<"Enter students name"<<endl;
cin>>x;
cout<<"Enter grade"<<endl;
cin>>c;


}
cout<<setw(5)<<a<<setw(5)<<x<<setw(5)<<c<<endl;

for(int e=0; e<=a; e++)
{
influte>>C1>>C2>>C3;
cout<<setw(10)<<C1<<setw(10)<<C2<<setw(10)<<C3<<endl;

}
influte>>C1>>C2>>C3;
cout<<setw(10)<<C1<<setw(10)<<C2<<setw(10)<<C3<<endl;

influte.close();


system("pause");

return 0;

}


Error 1: Line 8 and 27 conflict with line 31; You're redefining a previously defined variable.
Error 2: Inside the for loop of Line 31, you have two increments. You're going to cause overflow.
Error 3: For loop again, your loop condition is unreliable. It can easily cause overflow.
Warning: Global variables are highly undesirable for any program. Move your integers and c-strings into the scope of main.
Warning: std::string does not play well with cin directly. Use std::getline() part of the std::string library.
Warning: Do not use cin>> with cstrings. Use cin.getline().
Warning: You never check if the ifstream file exists. This can cause future problems. Add a is_open() check to your program before operations on the file.

Suggestions. Use better names for your integers. a,b,c,d,e may be easy to type, but I can't follow their purpose in a program easily. If e is your counter or increment call it counter or i in the loops.
If a is the number of entries to be entered, call it inputCount or something similar. Write source code for you to read, not for the program. Its going to be 0s and 1s when its done. You should make it readable for yourself.
Topic archived. No new replies allowed.