Strukturadagi bir qatorni qidirish

OK, men bu ishni bajarish uchun ishlayapman, shuning uchun kimdir menga yordam berishi mumkin, men foydalanuvchiga so'rashni xohlayman Stansiya nomini qidirishga harakat qilaman va agar u chiqmasa chiqsa chiqadi.

struct Trains 
{
    int Train_Id;                   //train ID
    string Station_Origin;             //Station of Origin
    string Destination_Station;        //Station of Destination
    int Departure_Time ;            //Departure Time
    int Arrival_Time ;              //Arrival Time
};

struct Trains  myArray[10];

struct station
{
    string intermediate_station1;      //intermediate_station1
    int Arrival_time1;            //Arrival time to station1 
    string intermediate_station2;      //intermediate_station2
    int Arrival_time2;            //Arrival time to station2 
    string intermediate_station3;    //intermediate_station1
    int Arrival_time3;            //Arrival time to station3   
};


struct station myArray1[3];

/*****************************************************************************/

int main ()
{
     /*  Setting up Train and Station Information  */ 
    int N_TRAIN;
    int n; 
    int a;

    do 
    {
         cout  << " Enter number of Trains on Track: " <> N_TRAIN;
         cout << endl;        
    }while(N_TRAIN > 10 || N_TRAIN < 0);

    for(n=0; n < N_TRAIN; n++)
    {
        while((cout<<" Enter Train ID: ")&&( (cin>>myArray[n].Train_Id)||myArray[n].Train_Id <0))
        {
            cout<<" Invalid Input! Please Enter Train ID: "<<< " Name of Station of Origin: ";
        cin >> myArray[n].Station_Origin;

        cout << " Name of Destination Station: ";
        cin >> myArray[n].Destination_Station;

        while((cout<<"Enter Departure Time: Please Enter 24hr!")&&(!(cin>>myArray[n].Departure_Time)||myArray[n].Departure_Time < 0))
        {
            cout<<" Invalid Input! Enter Departure Time: Please Enter 24hr !"<<<" Enter Arrival Time: Please Enter 24hr! ")&&(!(cin>>myArray[n].Arrival_Time)||myArray[n].Arrival_Time < 0))
        {
            cout<<" Invalid Input! Enter Arrival Time: Please Enter 24hr! "<<< " Name of Station of intermediate station1: ";
        cin >> myArray1[a].intermediate_station1;    

        while((cout<<" Enter Arrival Time For intermediate station1: Please Enter 24hr! ")&&(!(cin>>myArray1[a].Arrival_time1)||myArray1[a].Arrival_time1 < 0))
        {
            cout<<" Invalid Input! Enter Arrival Time: Please Enter 24hr! "<<< " Name of Station of intermediate station2: ";
        cin >> myArray1[a].intermediate_station2;


        while((cout<<" Enter Arrival Time For intermediate station2: Please Enter 24hr! ")&&(!(cin>>myArray1[a].Arrival_time2)||myArray1[a].Arrival_time2 < 0))
        {
            cout<<" Invalid Input! Enter Arrival Time For intermediate station2: Please Enter 24hr!"<<< " Name of Station of intermediate station3: ";
        cin >> myArray1[a].intermediate_station3;    

        while((cout<<" Enter Arrival Time For intermediate station3: Please Enter 24hr!")&&(!(cin>>myArray1[a].Arrival_time3)||myArray1[a].Arrival_time3 < 0))
        {
            cout<<" Invalid Input! Enter Arrival Time For intermediate station3: Please Enter 24hr!"<< N_TRAIN ;n++)
        {       

            cout << " Enter the Name of Departure Station: " ;
            cin >> origin;

            origin = searchfs();
            if (origin = myArray[n].Station_Origin )
               cout << "Trains Departs " << " " <<< "at" << " " << myArray[n].Departure_Time << " " << " Hours " <<< "Trains Departs " << " " <<< "at" << " " << myArray[n].Departure_Time << " " << " Hours " <<< "Trains Departs " << " " <<  myArray1[a].intermediate_station1<< "at" << " " << myArray1[a].Arrival_time1 << " " << " Hours " <<< "Trains Departs " << " " <<  myArray1[a].intermediate_station2 << "at" << " " << myArray1[a].Arrival_time2 << " " << " Hours " <<< "Trains Departs " << " " <<  myArray1[a].intermediate_station3<< "at" << " " << myArray1[a].Arrival_time3 << " " << " Hours " <<< " Train doesnt not Depart at "<< " " << origin << endl;
    }
}
7
xato nima.
qo'shib qo'ydi muallif rerun, manba
Asosiy talablar qanday? Haqiqatda 3 stantsiya bo'lishi kerakmi?
qo'shib qo'ydi muallif Thomas Matthews, manba
Shuningdek, loop sharoitida cout ni kiritmang, bu shunchaki bosh karıştırıcı.
qo'shib qo'ydi muallif Mooing Duck, manba
Bu bizni tashlab yuborish uchun juda ko'p kod, bu sizning munosabatingiz haqida nima ish qilmaganligi haqida juda kam ma'lumot.
qo'shib qo'ydi muallif wkl, manba
@Thilo - afsus, aslida asl tahrirlarimdan biri bo'lgan - noto'g'ri formatlash usullaridan foydalanilgan.
qo'shib qo'ydi muallif wkl, manba
Bundan tashqari, siz HTML elementlarini haqiqiy belgi bilan almashtira olasiz - bu sizning kodingizni juda o'qiydi. Masalan, & lt; o'rniga oddiygina < yozing
qo'shib qo'ydi muallif Thilo, manba
Ha, ushbu dasturni osonlashtirish uchun Origin stantsiyasiga va maqsadli stantsiyaga ega bo'lish maqsadga muvofiq, har bir rekord 3 qidiruv stantsiyaga ega.
qo'shib qo'ydi muallif David, manba

2 javoblar

Bir necha joylarda quyidagi misolga o'xshash (er-xotin == ) tenglikni tekshirishni nazarda tutgan vazifangiz (yagona = ) kabi ko'rinadi:

if (origin = myArray[n].Station_Origin)

Bundan tashqari Station_Origin va intermediate_station1/2/3 kodlari origin sifatida belgilab qo'yilgan bo'lsa, std :: string Bir int . Siz string ni int ga tayinlash yoki solishtirishga harakat qilyapsiz.

2
qo'shib qo'ydi
@David: Siz ko'rsatgan kod bo'yicha faqat ikkita qiymatni solishtirishni istagan joylarda = o'rniga == operatorini ishlating. Bunga qo'shimcha ravishda, origin> ni mag'lubiyatga o'zgaruvchiga o'zgartirishni xohlaysiz. Bundan tashqari, searchfs() funktsiyasini mag'lubiyatga qaytarish uchun o'zgartirishni bildiradi.
qo'shib qo'ydi muallif Blastfurnace, manba
Ishlay olishim uchun ushbu qidiruvni tuzatish uchun nima qilishim kerak, chunki men bu ishni bajaradigan har bir narsaga ega emasman. Dasturni amalga oshirishni istagan narsa, Stantsiya nomi agar keyingi Stringga bormasa va u keyingi Stringga bormasa, u holda String-ga murojaat qilinsa, stantsiya nomini kiritishni tanlashi mumkin. agar uning topilmasidan chiqmagan bo'lsa, stantsiya topiladi.
qo'shib qo'ydi muallif David, manba

Siz bizga nima ekanligini deb aytmadingiz, shuning uchun faqat kodni skanerlash orqali taxmin qilishimiz mumkin. Meni urgan narsa:

for(n=0; n < N_TRAIN; n++)
{
    ...
}      
else if (choice == 3)
{
}

va tanlash aniqlanmagan Mumkin bo'lgan eng ko'p xato xabarlarni qanday hal qilmoqchisiz, so'ngra sizni qiynayotgan muayyan narsalarni bizga ayting.

0
qo'shib qo'ydi
OK I-n dan int ga stringni o'zgartirayapman.() Ichida tushunolmaydigan narsa "origin = Searchfs ()" bilan ()
qo'shib qo'ydi muallif David, manba