mercredi 27 juillet 2022

How to print only once from array and ignore duplicate string with same id and value [closed]

I have an array with multiple of the same id which corresponds to a given name. But I only want it to print once. How can I do so? My current codes outputs this -> Current output

What I want my output to look like -> desired output

char dummy;
istringstream iss(line); // using istringstream to read directly from line
iss >> dummy >> citya >> dummy >> cityb >> dummy >> dummy >> cityc >> dummy >> city;
cityarray[cityb][citya] = cityc;
if (cityc == 3)
{
    city = "Big_City";
    cout << "City Name  :  " << city << endl;
    cout << "City Id    :  " << cityc << endl;
}
else if (cityc == 2)
{
    city = "Mid_City";
    cout << "City Name  :  " << city << endl;
    cout << "City Id    :  " << cityc << endl;
}
else if (cityc == 1)
{
    city = "Small_City";
    cout << "City Name  :  " << city << endl;
    cout << "City Id    :  " << cityc << endl;
}

Aucun commentaire:

Enregistrer un commentaire