Need help, with my loop
The Current Code I have is:
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
|
int main(){
int train_weight, total_weight=0, train_num, counter=0;
float train_length,total_length ;
string Train_type;
ifstream train_in;
train_in.open("Test.txt");
train_in >> train_num;
cout <<setw(5)<<" "<<"Data for Train Number "<<train_num<<endl;
cout <<setw(5)<<" "<<"Car Length Car Weight"<<endl<<endl<<endl;
if (train_in.is_open())
{
while(train_in.good()){
train_in >> train_length;
train_in >> train_weight;
cout<<setw(12)<<train_length<<setw(15)<<right<<train_weight<<endl;
total_weight = train_weight + total_weight;
total_length = train_length + total_length;
counter++;
}
train_in.close();
}
cout<<endl<<endl;
system("pause");
return 0;
}
|
I just want it not to loop the last number twice, any help will be appreciated, thanks
Hi,
I tested it on g++ (linux) and it's working fine.
could you post your Test.txt ?
Topic archived. No new replies allowed.