Enviado em 06/09/2013 - 11:33h
Pessoal, sou novo aqui, mas já quero postar uma dúvida que estou tendo em um exercício de C++ na faculdade, é algo meio bobo, mas ainda estamos num nível mais básico então, se puderem ajudar.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct carro
{
string nome;
int altura;
int largura;
float potencia;
};
int main ()
{
struct carro car;
float soma;
float media;
int opcao = 0;
int cont = 0;
string linha;
ifstream leitura;
ofstream escreve;
escreve.open("carros.txt");
if (!escreve.is_open())
{
cout << "Não foi possível abrir o arquivo";
return 1;
}
leitura.open("carros.txt");
if (!escreve.is_open())
{
cout << "Não foi possível abrir o arquivo";
return 1;
}
cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "|||| MENU ||||" << endl;
cout << "|||| ||||" << endl;
cout << "|||| 1 - Entrar novo carro ||||" << endl;
cout << "|||| 2 - Listar carros ||||" << endl;
cout << "|||| 3 - Fechar programa ||||" << endl;
cout << "|||| ||||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl;
cout << "||||||||||||||||||||||||||||||||||||||||||||" << endl << endl;
while (true)
{
cout << "Digite sua opcao: ";
cin >> opcao;
if (opcao == 1)
{
cout << "Caracteristicas do carro " << endl;
cout << "Digite o nome do carro: ";
cin >> car.nome;
cout << "Digite a altura: ";
cin >> car.altura;
cout << "Digite a largura: ";
cin >> car.largura;
cout << "Digite a potencia: ";
cin >> car.potencia;
escreve << car.nome;
escreve << " ";
escreve << car.altura;
escreve << " ";
escreve << car.largura;
escreve << " ";
escreve << car.potencia << endl;
}
if (opcao == 2)
{
cout << ("\n Nome Altura Largura Potencia\n");
cout << ("--------------------------------------------------------------\n");
while (!leitura.eof()){
getline(leitura, linha);
cout << linha << endl;
}
cout << ("--------------------------------------------------------------\n");
}
if (opcao == 3)
{
cout << endl << "||||| Obrigado por utilizar nosso software |||||" << endl;
cout << "||||| Volte sempre que precisar |||||" << endl;
return false;
}
if (opcao != 1 && opcao !=2 && opcao !=3){
cout << "Opcao inexistente, tente novamente. " << endl << endl;
}
}
escreve.close();
leitura.close();
}
Servidor de Backup com Ubuntu Server 24.04 LTS, RAID e Duplicati (Dell PowerEdge T420)
Visualizar câmeras IP ONVIF no Linux sem necessidade de instalar aplicativos
Atualizar Debian Online de uma Versão para outra
Dica para encontrar diversos jogos Indies criativos
Instalando Discord no Debian 13
Instalar driver Nvidia no Debian 13
Redimensionando, espelhando, convertendo e rotacionando imagens com script
Dificuldade com Ocs 2.12.3 no Debian 13 com Apache2 - Can't load ... (4)
paginação dos favoritos não funciona no vivaolinux[BU... (4)