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:
#include<iostream>
#include<string>
#include<fstream>
#include<stdlib.h>
usingnamespace 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 ://>/>