Originariamente inviato da oregon
Manca la dichiarazione di tutte le variabili e il codice non viene compilato ... fornisci un testo compilabile ...
Scusate, ecco qui:
codice:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
fstream tesi ("tesi.txt", fstream::in | fstream::out);
fstream studenti ("studenti1.txt", fstream::in | fstream::out);
if(!tesi.is_open()) {
cout << "Il file tesi.txt non esiste\n";
return -1;
}
if(!studenti.is_open()) {
cout << "Il file studenti1.txt non esiste\n";
return -1;
}
int sost,nnsost,voto,media,somma,ms=0,mt=0,z=0;
char nomesame[256],matricola_tesi[256], nome[256], matricola_studente[256];
while (!tesi.eof()) {
tesi.getline(matricola_tesi, 256);
cout<<matricola_tesi<<endl;
mt=0;z=0;
while(matricola_tesi[z]!='\0'){
mt+=(int)matricola_tesi[z]-(int)'0';
//cout<<k<<endl;
mt*=10;
z++;
}
mt=mt/10;
cout<<mt<<endl;
system("pause");
tesi.getline(nome, 256);
cout<<nome<<endl;
system("pause");
while (!studenti.eof()) {
cout<<"SONO SU"<<endl;
//int b=studenti.tellg();
//int l=b-8;
//if(b!=0) studenti.seekg (l, ios::beg);
studenti.getline(matricola_studente, 256);
cout<<matricola_studente<<endl;
z=0;ms=0;
while(matricola_studente[z]!='\0'){
ms+=(int)matricola_studente[z]-(int)'0';
//cout<<k<<endl;
ms*=10;
z++;
}
ms=ms/10;
cout<<ms<<endl;
system("pause");
studenti.getline(nome, 256);
cout<<nome<<endl;
studenti>>sost;
cout<<sost<<endl;
studenti>>nnsost;
cout<<nnsost<<endl;
//cout<<studenti.tellg()<<endl;
somma=0;
media=0;
int i=0;
while(i<sost){
studenti>>nomesame;
cout<<nomesame<<endl;
studenti>>voto;
cout<<voto<<endl;
somma+=voto;
i++;
}
media=(somma/sost);
cout<<media<<endl;
//cout<<studenti.tellg()<<endl;
if (ms==mt) {
cout << "ok " << ms << " "<<media<<"\n";
break;
}
cout<<"TORNO SU"<<endl;
}
cout<<"RIPETO IL FILE"<<endl;
studenti.clear();
studenti.seekg (0, ios::beg);
}
studenti.close();
tesi.close();
system("pause");
return 0;
}