Write/read stack in file

So i got this program to do and i am stuck..
The main point is to build a program that writes in file several changing bureaus
with name and address for them, several currency and its buy/sell values
and some other functions so i managed to do that but i cannot write properly and cant read at all..
here is my code:
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
 #include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
using namespace std;
int n,i,g;
int pos=0,posi=0;//pos is my counter for the bureaus and posi is for the currencies 
struct valuta
{
	string ime;// this is the name of the currency 
	double kupuva;// the buy value
	double prodava;// the sell value
};
struct bura
{
	string ime;//this is the name of the bureau 
	string adres;//the address
	valuta val[10];
};
bura b[30];
void regis()
{
	cout<<"vavedete broq na burata:";//here i input the number of  bureaus
	cin>>n;
	cout<<"\n vavedete broq na valutite v burata:";/the number of currency 
	cin>>g;
	for(i=0;i<n;i++)
	{
		cin.ignore();
	cout<<"\n vavedete imeto na buroto:";//name input
	getline(cin,b[pos].ime);
	cout<<"\n vavedete adresa na buroto:";//address input
	getline(cin,b[pos].adres);
	for(int j=0;j<g;j++)
	{
	cout<<"\n vavedete imeto na-"<<j+1<<"-valuta:";//currency name input
	cin>>b[pos].val[posi].ime;
	cout<<"\n vavedete kurs kopuva:";//buy value 
	cin>>b[pos].val[posi].kupuva;
	cout<<"\n vavedete kurs prodava:";//sell value
	cin>>b[pos].val[posi].prodava;
	posi++;
	}
	pos++;
	}
		ofstream buras("buras.txt",ios::app);
	if(buras.is_open())
	for(i=pos-n;i<pos;i++)
	{
		buras<<b[i].ime<<endl;
		buras<<b[i].adres<<endl;
		for(int j=posi-g;j<posi;j++)
		{
		buras<<b[i].val[j].ime<<endl;
		buras<<b[i].val[j].kupuva<<endl;
		buras<<b[i].val[j].prodava<<endl;
		}
	}
	buras.close();
}
void akt()
{
	string imee;
	string valu;
	cin.ignore();
	cout<<"\n vavedete imeto na buroto v koeto iskate da aktualizirate informaciq:";
	getline(cin,imee);
	for(i=0;i<pos;i++)
	if(imee==b[i].ime)
	{
		cout<<"\n vavedete valutata koqto iskate da aktualizirate:";
		cin>>valu;
		for(int j=0;j<posi;j++)
		if(valu==b[i].val[j].ime)
		{
			cout<<"\n vavedete noviq kurs kopuva:";
			cin>>b[i].val[j].kupuva;
			cout<<"\n vavedete noviq kurs prodava:";
			cin>>b[i].val[j].prodava;
		}
	}
		ofstream buras("buras.txt");
	if(buras.is_open())
	for(i=pos-n;i<pos;i++)
	{
		buras<<b[i].ime<<endl;
		buras<<b[i].adres<<endl;
		for(int j=posi-g;j<posi;j++)
		{
		buras<<b[i].val[j].ime<<endl;
		buras<<b[i].val[j].kupuva<<endl;
		buras<<b[i].val[j].prodava<<endl;
		}
	}
	buras.close();
}
void print()
{
	string valutaa;
	cout<<"\n vavedete valuta koqto iskate da izvedete:";
	cin>>valutaa;
	cout<<"\n kursovete na valutata vyv vsi4ki bura e:"<<endl;
	for(i=0;i<pos;i++)
	for(int j=0;j<posi;j++)
	if(valutaa==b[i].val[j].ime)
	{
		cout<<"ime na buroto:"<<b[i].ime<<" ;adres na buroto:"<<b[i].adres<<";"<<b[i].val[j].ime<<"-kopuva:"<<b[i].val[j].kupuva<<"-prodava:"<<b[i].val[j].prodava<<endl;
	}
}
void minimal()
{
	string valuu;
	string im;
	int min=99;
	cout<<"\n vavedete valuta koqto iskate da proverite:";
	cin>>valuu;
	for(i=0;i<pos;i++)
	for(int j=0;j<posi;j++)
	if(valuu==b[i].val[j].ime)
	{
	if(min>b[i].val[j].prodava)
	{
		min=b[i].val[j].prodava;
		im=b[i].ime;
	}
	}
	cout<<"minimalnata valuta koqto izbrahte se prodava vyv:"<<im;
}

int main()
{

	ifstream fin;
	fin.open("buras.txt");
	for(i=0;i<pos;i++)
	{
		fin>>b[pos].ime;
		fin>>b[pos].adres;
		for(int j=0;j<posi;j++)
		{
		fin>>b[pos].val[posi].ime;
		fin>>b[pos].val[posi].kupuva;
		fin>>b[pos].val[posi].prodava;
		posi++;
		}
		pos++;
	}
	fin.close();
	int choice;
	do
	{
             //here is just my menu i dont need to translate that 
		cout<<"\n 1.Vyvejdane na danni";
		cout<<"\n 2.Aktualizaciq na dannite za teku6tite kursove na burata";
		cout<<"\n 3.Izvejdane iformaciq za valutata ot vsi4ki bura";
		cout<<"\n 4.minimalna valuta";
		cout<<"\n 5.exit";
		cout<<"\n your choice:";
		cin>>choice;
		switch(choice)
		{
		case 1:regis();break;
		case 2:akt();break;
		case 3:print();break;
		case 4:minimal();break;
		case 5:break;
		}
	}while(choice!=5);
	return 0;
}

so and when i start it and try to input data this happens: 3 bureaus with 2 currencies in each one
first bureau
some street
-here is supposed to be the name of the 1st currency but it's blank
0
0
-name of the 2nd
0
0
second bureau
some street2
-same story
0
0
-and again..
0
0
third bureau
3rd street
euro
1
1.4
pound
2.2
2.4
on the third one everything is fine.. i think i have problems with my counters or my cycles but i cant seem to find it
i am asking for help :)/>/> and sorry the program is not on еnglish, but еnglish is not my native language
i hope you can solve it ://>/>
Last edited on
Topic archived. No new replies allowed.