question-what is wrong with this code

closed account (ShUk4iN6)
hey everyone what am I doing wrong its always giving me an error

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
#include<fstream>
using namespace std;
{

	if stream fin;
	int acctno, code;
	double amount,bal;
	fin.open("bank.dat");
	
	while(!fineof())
	{
		fin>>acctno>>code>>amount>>bal;
	
		if(code==1)

		else

		if(code==2)

		else

	cout<<"bad transssion code">>endl;
	}
	return 0;
}
it is ifstream, not if stream, the fin>> is wrong, you have to say cin>> and maybe your if's, i'm not sure
closed account (ShUk4iN6)
ok i got this far but its still giving me errors hannes i tried to type ifstream but its still saying that it is wrong


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
#include<fstream>
#include<iostream>
using namespace std;

int main()
{
	if stream fin;
	double balance, amount;
	int acctno,code;
	int i = 0;
	fin.open("bank.dat");

void deposit{
for (int i = 0;i++)
{
fout<<"How Much do you want to deposit?\n";
fin>> amount;
balance += amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}}

void withdraw{

	int deposit;
	int acctno;
for(int i = 0;i++)
{
if (balance =>0){
fout<<"How Much do you want to withdraw?\n";
fin>> amount;
balance -= amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
else{
fout<<"Insufficient Funds"
balance -=0;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
if(balance < 100.00){
balance -=10.00;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
}



do{
	fout<<"Account Number - Code(1 for deposit 2 for withdrawal)-Amount-Balance\n";
	fin>>acctno>>code>>amount>>balance;



	if (code== 1){
	Deposit;
	}else if (code== 2)
	Withdraw;
	}while(code !=1,2);
	{
		fout<<"Bad Transaction code\n";
	}
}

}


as far as i'm concerned you can't make functions inside the main function.
closed account (ShUk4iN6)
are you talking about int main()??
are you talking about int main()??


Pretty sure he is.

P.S. You may want to indent your code a little better, it's a little hard to read.
To be honest, there is so much wrong with that code that you need to get yourself a decent book and start from scratch. I mean that in the least possible offensive way. You are trying to run before you can even walk.
Last edited on
All of the functions that are inside main() need to be taken out of main and made their own stand-alone function. Also, if you place them after main(), you will have to declare them first.

Moreover, moving the functions into a proper place will not solve all your problems.

You should take the advice of Chewbob and buy a book on basic C/C++ programming, for you will never understand your own code until you at least learn the basics.
closed account (ShUk4iN6)
I have a c++ book and it's been only 3 weeeks I started programming. So you guys are saying that I shoul take the functions out of the int main() and declare the variables in void Am I right??
closed account (ShUk4iN6)
ok i got this much but i am still doing something wrong can someone pls help me
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
#include<fstream>
#include<iostream>
using namespace std;

struct member{
    string name;
    double balance;
    int number;
}

void deposit{
for (int i = 0;i++)
{
	double balance, amount;
	int acctno,code;
	int i = 0;

fout<<"How Much do you want to deposit?\n";
fin>> amount;
balance += amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}}

void withdraw{

	int deposit;
	double balance, amount;
	int acctno,code;
	int i = 0;
for(int i = 0;i++)
{
if (balance =>0){
fout<<"How Much do you want to withdraw?\n";
fin>> amount;
balance -= amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
else{
fout<<"Insufficient Funds"
balance -=0;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
if(balance < 100.00){
balance -=10.00;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
}
    
do {
    cout << "Enter input data file name:";
    cin >> filename;
    fin.open("bank.dat");
    if (!fin) { 
        cout << "Unable to open " << filename << endl;
    }
} while (!fin);

do{
	fout<<"Account Number - Code(1 for deposit 2 for withdrawal)-Amount-Balance\n";
	fin>>acctno>>code>>amount>>balance;



	if (code== 1){
	Deposit;
	}else if (code== 2)
	Withdraw;
	}while(code !=1,2);
	{
		fout<<"Bad Transaction code\n";
	}
return 0;

}
You have just gone and made it worse.
Where is main?
What is fout?
What is fin?
Assuming they are your file streams, why are you trying to interact with them as though they are the standard input/output?
You have no () after your function calls or even in their declarations.
Your loops at the bottom make no sense. You are getting the syntax wrong on so many things.

It may sound harsh but it's true. What is the name of the book you are using?

Use this: http://www.cplusplus.com/doc/tutorial/
Start from the beginning and work your way through before attempting anything like this.
closed account (ShUk4iN6)
ok all i want is to use fin or cin but it says that i didnt declare them and i declared acctno but its saying that i didnt declare it why??
ok i will start from the beginning


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
#include<fstream>
#include<iostream>
#include<vector>
using namespace std;

struct member{
    string name;
    double balance;
    int number;
	int acctno;
}

void deposit(vector<acctno>){
for (int i = 0;i++)
{
	double balance, amount;
	int acctno,code;
	int i = 0;

fout<<"How Much do you want to deposit?\n";
fin>> amount;
balance += amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}}

void withdraw(vector<acctno>){

	int deposit;
	double balance, amount;
	int acctno,code;
	int i = 0;
}
for(int i = 0;i++)
{
if (balance =>0){
fout<<"How Much do you want to withdraw?\n";
fin>> amount;
balance -= amount;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
else{
fout<<"Insufficient Funds"
balance -=0;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
if(balance < 100.00){
balance -=10.00;
fout<<" "<<acctno<<" "<<code<<" "<<amount<<" "<<balance<<"\n";
}
}





int main (int argc, char*argv[]) {        
    ofstream memberfile;
    int code;
	int filename;
    memberfile.open ("bank.dat");
    cout << "Welcome to the Bank.";
do {
	
	fout<<"Account Number - Code(1 for deposit 2 for withdrawal)-Amount-Balance\n";
	fin>>acctno>>code>>amount>>balance;



	if (code== 1){
	Deposit (membervector);
	}else if (code== 2){
	Withdraw (membervector);
	}while(code !=1,2);
	{
		fout<<"Bad Transaction code\n";
	}
}
return 0;

}
Topic archived. No new replies allowed.