Error on method of Menu Class

Hi boys,
i have an error that i can undestand:

i have a method       " ControlloreClienti::stampaListaClienti(vector<Cliente *> c)"
that take a vector(result of a search) and from this built a string inj witch are appended every item of the vector+"esci"

After i have a class menu that take on input this string and built a textual menu.
My program,in runtime have a block in the line "sceltaCliente.setSceltaUtente();"

I have also another method "  " ,so similar,in witch the same code doesn't give problem

I attach my code below:

void ControlloreClienti::stampaListaClienti(vector<Cliente *> c) {                      
    string s = "";
    for(int i = 0; i < c.size(); i++) {                  
        s.append((c[i])->getCodiceFiscale() +
                 Utility::riempimento(15 - ((c[i])->getCodiceFiscale()).size(), ' ')+
                 (c[i])->getNome() +
                 Utility::riempimento(15 - ((c[i])->getNome()).size(), ' ') +
                 (c[i])->getCognome() +
                 Utility::riempimento(15 - ((c[i])->getCognome()).size(), ' ') +
                 (c[i])->getVia() +
                 Utility::num2string((c[i])->getNumeroCivico()) +
                 Utility::riempimento(15 - (Utility::num2string((c[i])->getNumeroCivico())).size(), ' ') +
                 Utility::num_long2string((c[i])->getCap()) +
                 Utility::riempimento(15 - ((c[i])->getVia()).size(), ' ') +
                 (c[i])->getCitta() +
                 Utility::riempimento(15 - ((c[i])->getCitta()).size(), ' ') +        
                 (c[i])->getProvincia() +
                 Utility::riempimento(15 - ((c[i])->getProvincia()).size(), ' ') +
                 (c[i])->getNazione() +
                 Utility::riempimento(15 - ((c[i])->getNazione()).size(), ' ') +
                 Utility::num_long2string((c[i])->getNumeroCartaCredito()) +
                 Utility::riempimento(15 - (Utility::num_long2string((c[i])->getNumeroCartaCredito())).size(), ' ') +
                 Utility::num2string((c[i])->getNumeroNoleggi()) +
                 Utility::riempimento(15 - (Utility::num2string((c[i])->getNumeroNoleggi())).size(), ' ') +
                 Utility::num_long2string((c[i])->getChilometriPercorsi()) +
                 Utility::riempimento(15 - (Utility::num_long2string((c[i])->getChilometriPercorsi())).size(), ' ') +
                 Utility::num_long2string((c[i])->getSpesaTotale()) +
                 Utility::riempimento(15 - (Utility::num_long2string((c[i])->getSpesaTotale())).size(), ' ') +
                 (c[i])->getTarga() +
                 Utility::riempimento(15 - ((c[i])->getTarga()).size(), ' '));                        
        s.append("|");                    
    }
    s.append("ESCI");
    Menu sceltaCliente(s, "VISUALIZZA LE INFORMAZIONI DI UN Cliente");
    do {
        system("cls");
        system("pause");
        cout<<s;system("pause");
        sceltaCliente.setSceltaUtente();/* e qui il problema*/system("pause");
        if(sceltaCliente.getSceltaUtente() > 0 && sceltaCliente.getSceltaUtente() <= c.size()) {system("pause");
            (c[sceltaCliente.getSceltaUtente() - 1])->stampaCliente();
            cout << endl << "\n\nCliente " << sceltaCliente.getSceltaUtente()
                         << "   di   " << c.size() << "." << endl;
            system("pause");
        }
    }
    while(sceltaCliente.getSceltaUtente() != 0);
    return;
}


void ControlloreVeicoli::stampaListaVeicoli(vector<Veicolo *> v) {
    string s = "";
    for(int i = 0; i < v.size(); i++) {
        s.append((v[i])->getCategoria() +
                 Utility::riempimento(15 - ((v[i])->getCategoria()).size(), ' ') +
                 (v[i])->getCasaCostruttrice() +
                 Utility::riempimento(15 - ((v[i])->getCasaCostruttrice()).size(), ' ') +
                 (v[i])->getModello() +
                 Utility::riempimento(15 - ((v[i])->getModello()).size(), ' ') +
                 (v[i])->getTarga());
        s.append("|");
    }
    s.append("ESCI");
    Menu scegliVeicolo(s, "VISUALIZZA LE INFORMAZIONI DI UN VEICOLO");
    do {
        system("cls");
        scegliVeicolo.setSceltaUtente();
        if(scegliVeicolo.getSceltaUtente() > 0 && scegliVeicolo.getSceltaUtente() <= v.size()) {
            (v[scegliVeicolo.getSceltaUtente() - 1])->stampaVeicolo();
            cout << endl << "\n\nVeicolo " << scegliVeicolo.getSceltaUtente()
                         << "   di   " << v.size() << "." << endl;
            system("pause");
        }
    }
    while(scegliVeicolo.getSceltaUtente() != 0);
    return;
}
zprestazAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteHCommented:
Can you please show the code for setSceltaUtente () of class Menu.  

A hint: not everyone will understand "e qui il problema" - The problem is here.
0
zprestazAuthor Commented:
Code of class menu:

// Menu.cpp

#include "Menu.h"
#include "Utility.h"

//costruttore
Menu::Menu( string o, string t ="", string dv = "20", string ev = "0")
   : sceltaUtente("Seleziona",dv,ev,"-1")
{
  titolo = ( t=="" ? "MENU'" : t );
  escapeValue = ev;
 
  int index;
  do {
     index = o.find("|");
     if ( index != string::npos ) {  // se non ho trovato "|" ...
        opzioni.push_back( o.substr(0,index) );
        o = o.substr(index+1);
     }
     else {
        opzioni.push_back( o );
        o = "";
     }
  } while ( !o.empty() );
}

//la scelta
bool Menu::valutaOpzione()    
{
  if  ( sceltaUtente.getDato() == atoi(escapeValue.c_str()) )
      return true;

  if  ( sceltaUtente.getDato() < 0 || sceltaUtente.getDato() > opzioni.size() )
     return  false;
  else
     return true;
}


//costruzione menù grafico
void Menu::setSceltaUtente( bool clean=true , bool main = false )
{
    do {
        if (clean) system("cls");
        cout << endl;
        cout << Utility::riempimento(lunghezza, '^') << endl;
        cout << ">" << Utility::riempimento(lunghezza - 2, ' ') << "<" << endl;
        cout << ">" << Utility::riempimento((lunghezza - 2 - titolo.size()) / 2, ' ') << titolo;

        cout << (
            titolo.size() % 2 == 1 ?
            Utility::riempimento((lunghezza - titolo.size() - 2) / 2, ' ') :
            Utility::riempimento((lunghezza - titolo.size() - 2) / 2 + 1, ' ')
                 )
            << "<" << endl;

        cout << ">" << Utility::riempimento(lunghezza - 2, ' ') << "<" << endl;
        cout << Utility::riempimento(lunghezza, '^') << endl;
        cout << ">" << Utility::riempimento(lunghezza - 2, ' ') << "<" << endl;
        for(int i = 0; i < opzioni.size() - 1; i++)
                cout << ">      " << i + 1 << " )   " << opzioni[i]
                     << Utility::riempimento(lunghezza - opzioni[i].size() - 14, ' ') << "<" << endl;
        cout << ">" << Utility::riempimento(lunghezza - 2, ' ') << "<" << endl;

        cout << ">      0 )   " << opzioni[opzioni.size() - 1]
             << Utility::riempimento(lunghezza - opzioni[opzioni.size() - 1].size() - 14, ' ')
             << "<" << endl;
        cout << ">" << Utility::riempimento(lunghezza - 2, ' ') << "<" << endl;
        cout << Utility::riempimento(lunghezza, '^') << endl;
        cout << endl;

        sceltaUtente.setDato(false);
    }
    while ( !valutaOpzione() );
}


int Menu::getSceltaUtente()
{
    return sceltaUtente.getDato();
}
0
SteHCommented:
From that piece of code I would look deeper into while (!valutaOpzione()). Does this end? How about sceltaUtente.getData and .setDato?
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

zprestazAuthor Commented:
Can you explain better please.......................
do you want another piece of code or what??
0
SteHCommented:
At first I want to give you hints to find the error yourself. Only if this fails I might find the time to get into it more deeply. I suggest you to use a debugger to look at that line and whether it returns "true" at some time. For me knowledge of getDato and setDato prevent me from giving an answer.
0
zprestazAuthor Commented:
the point is that in void ControlloreVeicoli::stampaListaVeicoli(vector<Veicolo *> v) the problem doesn't exist....................,but in void ControlloreClienti::stampaListaClienti(vector<Cliente *> c) yes.............
the two methods are so identic......................the problem exists only in runtime...........and in function void ControlloreClienti::stampaListaClienti(vector<Cliente *> c) i've added system("pause") and i've find that the command that block the program is sceltaCliente.setSceltaUtente();

GetDato() and SetDato() are methods of class CasellaInt (derivated from Casella class) that i attack below.These class take data on input and check this input

#include <cmath>
#include "Casella.h"

extern bool admin;

//messaggio della richiesta di input
void Casella::showMessage() {
    if(admin)
        cout << messaggioRichiesta << "  -#>  ";
    else
        cout << messaggioRichiesta << "  -@>  ";
}

//costruttore
Casella::Casella(string mr, string dd, string ec, string d)
{
      messaggioRichiesta = mr;
      defaultDato = dd;
      escapeChar = ec;
      dato = d;

}

//lettura dato da tastiera
void Casella::setDato(bool repeat=true)
{

  do{
    errorMsg=string();
    char buffer[200];        
    showMessage();
    cin.getline(buffer,200,'\n'); //fino al RETURN, max 200 char
    dato = buffer;

    if (dato=="") {
        dato = defaultDato;
        return;
    }
    else
      if (dato!=escapeChar) {
        isValid();         //chiama la funzione virtuale, ovvero quella di ogni classe specifica
        if( Error() && repeat )
        {
//          cout << "\a\nErrore: " << getError() << endl;
//          system("pause");
//          system("cls");
        }
        if(!repeat) return;
      }
  }
  while( repeat && Error() );    

}

bool Casella::Error() {
    return !errorMsg.empty();
}


string Casella::getError()
{
  return errorMsg;
}

// CasellaInt.cpp

#include <cmath>
#include "CasellaInt.h"


     
//controllo specifico per la suddetta classe
void CasellaInt::isValid()
{

  bool esito=true;
  errorMsg=string();
  int start = ( ( dato.at(0) == '-' ) ? 1 : 0 );   //da dove deve partire se c'è il segno meno
  for (int i=start; i<dato.size(); i++)
     if ( !isdigit( dato.at(i) ) )
        {
          errorMsg= "Il dato inserito non e' un numero intero";
          esito=false;
          break;
        }
  if (!esito)
     dato = errorDato;
 
}  
   

   
//costruttore


CasellaInt::CasellaInt(string mr, string dd, string ec, string ed="")
   : Casella(mr,dd,ec,"")
{
      errorDato = ed;
}

//restituzione dato come numero    
int CasellaInt::getDato()
{
  return atoi( dato.c_str() );    //conversione stringa vecchio stile C
}
     

//restituzione dato come stringa

string CasellaInt::getDatoString(){
  return dato;
}
0
SteHCommented:
sceltaCliente.setSceltaUtente(); is called twice but with different menus. Now you say it blocks: this could mean that a loop never ends and there is only one while and one for loop inside which could possibly not end. The for loop has a predefined number ofiterations so you're left with the while loop. But it could be another function call within this function. Without all code it's difficult to tell but I prefer that you try it yourself  and I give some guidance.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.