initializers before for error

Hello everybody!
Our teacher asked us to write a program for a bank.[yes its a homework , but i already have written it all]
in this program we have to get some info. [first name, last name, bank account number, 10% interest and balance.] We should be able to print all the information, deposit money, take money and move money to other accounts.[we have total of ten accounts]
We haven't studied anything about class and the only libraries we know are iostream, math.h and string.
this is the code.
we have three errors
line 20 expected an initializer before for
line 20 expected ; befor ) token
line 89 expected } before input
i have no idea how to solve it. i'd appreciate it if you can help.

I apologize for the Persian parts.

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
  #include<iostream>
using namespace std;
#include<string.h>
struct bank{char fullname[40];
long int hesab;
long int card;
long int mojudi;
            };
void info(bank*);
long int searchhesab(bank A[],int,long int);
void bardasht(bank*,long int );
void enteghal(long int(*searchhesab)(bank A[],int n,long int x),bank*,long int,long int);
void soud(bank*);
int main(){	int i,t,y;
            long int B[i];
			char d;
		    long int x,v,p,q;
        bank B[10]
        
			for(i=0;i<10;i++){info(&B[i]);
			cout<<"shomarehesab(16 number)";
			cin>>x;
			 t=searchhesab(B,10,x);
			 if(t==-1){cout<<"shomarehesab not exist";
			 }
else{do{cout<<"what do you want to do 1-bardasht 2-soud&mojodi 3-enteghal";
     cin>>y;
    if(y==1){bardasht(&B[t],v);
		    }
    if(y==2){soud(&B[t])
	     	}
	if(y==3){enteghal(&B[t],p,q)
			}
	 cout<<"Are you need to continue? y/n ";
	      cin>>d;
		}while(d=='y');
   }		             }
   return 0;
         }
void info(bank*B){
                  cout<<"enter fullname";
                  cin.get(B->fullname,39);
                  cout<<"enter shomarehesab";
                  cin>>B->hesab;
                  cout<<"enter shomarecart";
                  cin>>B->card;
                  cout<<"enter mojudi";
                  cin>>B->mojudi;
                 }
long int searchhesab(bank A[],int n,long int x){int i;
	                  for(i=0;i<10;i++){if (B[i]->hesab==x){return i;
					                                        }
					                   }  
											     return -1;
                                                }
void bardasht(bank*,long int v ){long int w,z;
	                                 w=B[i]->mojudi;
	                                 cout<<"how much do you need?";
	                                 cin>>v;
	                                if(w>v){z=w-v;
	                                   cout<<"mablagh bardashti="<<v;
								        	} 
	                                else{cout<<"mojudi is not enough";
									    } 
								}
void enteghal(long int(*searchhesab)(bank A[],int n,long int x),bank*,long int q,long int p){long int r,a;
																									int u;
	                                      r=B[i]->mojudi;
	                                    cout<<"money for transfer? ";
	                                    cin>>q;
	                                    a=r-q
	                                  if(a>0){cout<<"shomare hesab maghsad";
	                                    cin>>p;
	                                    u=searchhesab(p);
	                                if(u!=-1){f=B[u]->mojudi;
	                                    cout<<"mojudi baghimande"<<"="<<a;
								        	}
	                                     else{cout<<"somare hesab not exsit";
									    	 }
	                                        }
							            else{cout<<"mojudi is not enough";
									        }
                                                                                               }          
void soud(bank*){long int j,b;
					double l=0.1;
             j=B[i]->mojudi
             b=j*l;
        cout<<"mojudi shoma ba 0.1 soud"<<b;
		 }
               


Bank b[10] doesn't have a ";" terminating that statement.

Line 8 has }; for no reason.
Last edited on
What is this formatting? If I was your instructor I'd give you a big fat zero. This is completely unreadable. Fix it immediately.

line 20 expected an initializer before for
You forgot a semicolon at the end of line 18.

line 20 expected ; befor ) token
Could be cascading error from the previous error.

line 89 expected } before input
You forgot a semicolon at the end of line 86.

PS: See what I mean? Niccolo is a very experienced programmer and he missed the struct on line 4.
Last edited on
Learn how to indent code. Seriously, your post was a mess!
https://en.wikipedia.org/wiki/Indentation_style

In particular, if you mix real tabs (character 9 or '\t') with spaces, then anywhere you end up printing it or posting it, it will look like your dog wrote it.

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
115
116
117
118
119
#include<iostream>
using namespace std;
#include<string.h>

struct bank {
  char fullname[40];
  long int hesab;
  long int card;
  long int mojudi;
};

void info(bank *);
long int searchhesab(bank A[], int, long int);
void bardasht(bank *, long int);
void enteghal(long int (*searchhesab) (bank A[], int n, long int x), bank *, long int, long int);
void soud(bank *);

int main()
{
  int i, t, y;
  long int B[i];
  char d;
  long int x, v, p, q;
  bank B[10]

  for (i = 0; i < 10; i++) {
    info(&B[i]);
    cout << "shomarehesab(16 number)";
    cin >> x;
    t = searchhesab(B, 10, x);
    if (t == -1) {
      cout << "shomarehesab not exist";
    } else {
      do {
        cout << "what do you want to do 1-bardasht 2-soud&mojodi 3-enteghal";
        cin >> y;
        if (y == 1) {
          bardasht(&B[t], v);
        }
        if (y == 2) {
          soud(&B[t])
        }
        if (y == 3) {
          enteghal(&B[t], p, q)
        }
        cout << "Are you need to continue? y/n ";
        cin >> d;
      } while (d == 'y');
    }
  }
  return 0;
}

void info(bank * B)
{
  cout << "enter fullname";
  cin.get(B->fullname, 39);
  cout << "enter shomarehesab";
  cin >> B->hesab;
  cout << "enter shomarecart";
  cin >> B->card;
  cout << "enter mojudi";
  cin >> B->mojudi;
}

long int searchhesab(bank A[], int n, long int x)
{
  int i;
  for (i = 0; i < 10; i++) {
    if (B[i]->hesab == x) {
      return i;
    }
  }
  return -1;
}

void bardasht(bank *, long int v)
{
  long int w, z;
  w = B[i]->mojudi;
  cout << "how much do you need?";
  cin >> v;
  if (w > v) {
    z = w - v;
    cout << "mablagh bardashti=" << v;
  } else {
    cout << "mojudi is not enough";
  }
}

void enteghal(long int (*searchhesab) (bank A[], int n, long int x), bank *, long int q, long int p)
{
  long int r, a;
  int u;
  r = B[i]->mojudi;
  cout << "money for transfer? ";
  cin >> q;
  a = r - q if (a > 0) {
    cout << "shomare hesab maghsad";
    cin >> p;
    u = searchhesab(p);
    if (u != -1) {
      f = B[u]->mojudi;
      cout << "mojudi baghimande" << "=" << a;
    } else {
      cout << "somare hesab not exsit";
    }
  } else {
    cout << "mojudi is not enough";
  }
}

void soud(bank *)
{
  long int j, b;
  double l = 0.1;
  j = B[i]->mojudi b = j * l;
  cout << "mojudi shoma ba 0.1 soud" << b;
}


1
2
3
4
5
  int i, t, y;
  long int B[i];
  char d;
  long int x, v, p, q;
  bank B[10]

1. B has two different types.
2. The first B is being sized by the uninitialised value in i
3. Aside for loop variables (like i, j) and say coordinates (x,y), you really need to lay off the single letter identifiers.
The error codes are very easy to read in this case.

LOTS of lines with missed semicolons all over the code. You should have received more errors.

The indentations and format is simply horrible to look at, you need to work on that. An IDE like Visual Studio might help you format your code better.

Also, lots of things in the code don't actually work. In the function "enteghal" you try to use "B", a variable you never passed in as a parameter/argument.

First though, you REALLY have to fix how this code looks. I got lost looking for brackets.
Topic archived. No new replies allowed.