Jump to content

Recommended Posts

Posted

boa noite! Estou aqui com um problema com o meu programa. Quando corro, estou a introduzir os dados e quando chega à introdução dos dados do segundo livro, o programa salta para o dado seguinte.

#include <iostream>
using namespace std;
const int MAX = 100;
//========================================================
struct livro{
string titulo;
string autor;
unsigned int ano;
float custo;
};
//========================================================
void le_livro(livro & um){
cout << "Indique o titulo do livro:" << endl;
getline(cin, um.titulo);
cout << "Indique o autor de " << um.titulo << ":" << endl;
getline(cin, um.autor);
cout << "Indique o ano de " << um.titulo << ":" <<endl;
cin >> um.ano;
cout << "Indique o custo de " << um.titulo << ":" << endl;
cin >> um.custo;
cin.ignore();

}
//========================================================
void carrega(livro biblio[], int tam){
for(int i = 0; i < tam; i++) le_livro(biblio[i]);
}
//========================================================
void mostra(livro tab[], int tam){
for(int i = 0; i < tam; i++){
	cout << tab[i].titulo << ";" << tab[i].autor << ";" << tab[i].ano << ";" << tab[i].custo << endl;
}
}
//========================================================
int main(){
int dim = 3;
livro bib[MAX];
carrega(bib, dim);
mostra(bib, dim);
return 0;
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.