السلام عليكــم ورحمـة الله وبركاتــة ،،
لم اعرف ما هو الخطأ الموجود في البرنامج الذي قمت بكتابته
الهدف كود القراءة من ملف النصي التكست و استخدام جملة سوتش
لدينا القيم في ملف التكست وهي عبارة عن الايدي للبحيرة و متوسط وزن السمكة
Create a text file of the following data. called data.txt 1000 4.0 1000 2.0 1000 1.5 1010 2.0 1010 2.2 1010 1.9 1050 2.8 1050 4.2 1100 1.7 1100 1.6 1250 2.2 1250 4.5 1300 4.0 1300 5.1 1300 3.4 1350 1.1 1350 1.2 1350 2.0
الان الجدول الاتي فيه ايدي البحيرة و اسمها
Lake ID Lake Name --------------------------------------- 1000 Chemo 1010 Eddington 1050 Hopkins 1100 Toddy 1250 Branch 1300 Phillip 1350 Green
و المطلوب كالاتي جدول فيه الخانات الثلاث بالفراغات
ID............Lakename.............avg
الكود الي انا عامله طلع في اخطأء اول شيء لا يقرأ كل القيم
و لا يستفيد من عبارة switch في التحكم
#include <fstream>
#include <iostream>
using namespace std;
int main ( )
{
int lakeid; // Lake ID declartion
double fishwgt; // fish weight in pounds declartion
char LakeName; //Lake name in Charchter declartion
ifstream fin; // declare input file stream object
fin.open ("data.txt"); // open the file
if ( fin.fail( ) )
{ cerr << "open failure";
exit(1); // end the program with an error return code
}
fin >> lakeid >> fishwgt; // read the int lakeid and the double fishwgt values
switch (lakeid)
{
case 1000 : LakeName = "Chemo";
case 1010 : LakeName = 'Eddington';
case 1050 : LakeName = 'Hopkins';
case 1100 : LakeName = 'Toddy';
case 1250 : LakeName = 'Branch';
case 1300 : LakeName = 'Phillip';
ase 1350 : LakeName = 'Green';
}
cout << lakeid <<"\t"<<fishwgt<<"\n";
fin.close ( );
return 0;
}

