Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 17
  1. #1

    C++ Carta Forbice Sasso

    Salve , il mio ho problema è che ho implementato un porgramma in cui un utente gioca contro il computer e faccio scegliere al computer di forma casuale mediante una funzione ma non so come devo fare per fare scegliere fra sasso carta e forbice all'utente avendo creato una variabile di tipo enum, In poche parole non so come fargli introdurre la sua scelta, perche pensavo potessi fare: cin>>sceltaUtente , ma vedo che non è possbile.
    grazie
    Marcos
    codice:
    #include <iostream>
    # include <cstdlib>
    #include <ctime>
    using namespace std;
    
    
    
    void jugada (int&);
    
    
    
    
    
    int main() {
    
    
    	int sceltaComputer;
    	srand (time(NULL));
    	enum  sceltaUtente { carta=1 , forbici, sasso};
    
    	cout<<"si cominicia il gioco:"<<endl;
    
    	jugada (sceltaComputer);
    	cout<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    	return 0;
    }
    
    
    void jugada (int& sceltaComputer)
    {
    	sceltaComputer = rand()%3+1;
    
    	if (sceltaComputer == 1){
    		cout<<"carta"<<endl;
    	}
    
    	if (sceltaComputer == 2){
    		cout<<"forbici"<<endl;
    	}
    
    	if (sceltaComputer == 3){
    		cout<<"sasso"<<endl;
    	}
    }

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802

    Re: C++ Carta Forbice Sasso

    Originariamente inviato da marcos666
    In poche parole non so come fargli introdurre la sua scelta, perche pensavo potessi fare: cin>>sceltaUtente , ma vedo che non è possbile.
    Non è possibile in che senso???
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  3. #3
    Come faccio a fargli inserire la sua scelta all'utente con enum,
    vorrei che l'utente scrivessi 1 ad esempio e quindi il programma stampassi carta, per poi poter fare il confronto con la scelta casuale del computer.
    grazie

  4. #4
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    Originariamente inviato da marcos666
    Come faccio a fargli inserire la sua scelta all'utente con enum,
    Una enum è solo una sequenza di interi, nient'altro...

    Originariamente inviato da marcos666
    vorrei che l'utente scrivessi 1 ad esempio e quindi il programma stampassi carta, per poi poter fare il confronto con la scelta casuale del computer.
    grazie
    Acquisisci la scelta dell'utente come intero (usando cin) e la confronti con l'intero generato dal computer, non capisco il problema...
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  5. #5
    Scusa che ti sto facendo diventare pazzo, in sostanza quello che voglio fare è: cin>>sceltaUtente; per pter fare inserire all'utente se vuole scegliere carta, forvici o sasso ma il debug me dice:

    codice:
    ../src/SASSO CARTA FORBICE.cpp: In function ‘int main()’:
    ../src/SASSO CARTA FORBICE.cpp:27: error: expected primary-expression before ‘;’ token
    make: *** [src/SASSO CARTA FORBICE.o] Errore 1

  6. #6
    Utente di HTML.it
    Registrato dal
    Jan 2011
    Messaggi
    15
    Scusami se te lo dico ma stai imparando c++ da solo o ti insegna un cane?!
    codice:
    /* Script Rayan94 */
    #include <cstdlib>
    #include <iostream>
    #include <ctime>
    #include <conio.h>
    
    using namespace std;
    
    int punti_giocatore=0,punti_computer=0;
    
    string jugada()
    {
        int sceltaComputer,max=3,min=1;
        string cout_Computer;
    	sceltaComputer =( rand() % (max-min+1) ) + min;
    
    	if (sceltaComputer == 1){
            cout_Computer="Sasso";
    	}
    
    	if (sceltaComputer == 2){
    		cout_Computer="Carta";
    	}
    
    	if (sceltaComputer == 3){
            cout_Computer="Forbici";
    	}
    	return cout_Computer;
    }
    
    void play(string sceltaComputer,string sceltaGiocatore)
    {
       if(sceltaComputer=="Sasso" && sceltaGiocatore=="Sasso")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+0;
           cout << "Parita'! " << endl << endl;
       }
       if(sceltaComputer=="Sasso" && sceltaGiocatore=="Carta")
       {
           punti_giocatore=punti_giocatore+1;
           punti_computer=punti_computer+0;
           cout << "Giocatore vince! " << endl << endl;                             
       }
       if(sceltaComputer=="Sasso" && sceltaGiocatore=="Forbici")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+1;
           cout << "Computer vince! " << endl << endl;                             
       }
       if(sceltaComputer=="Carta" && sceltaGiocatore=="Carta")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+0;
           cout << "Parita'! " << endl << endl;
       }
       if(sceltaComputer=="Carta" && sceltaGiocatore=="Forbici")
       {
           punti_giocatore=punti_giocatore+1;
           punti_computer=punti_computer+0;
           cout << "Giocatore vince! " << endl << endl;                             
       }
       if(sceltaComputer=="Carta" && sceltaGiocatore=="Sasso")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+1;
           cout << "Computer vince! " << endl << endl;                             
       }
       if(sceltaComputer=="Forbici" && sceltaGiocatore=="Forbici")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+0;
           cout << "Parita'! " << endl << endl;
       }
       if(sceltaComputer=="Forbici" && sceltaGiocatore=="Sasso")
       {
           punti_giocatore=punti_giocatore+1;
           punti_computer=punti_computer+0;
           cout << "Giocatore vince! " << endl << endl;                             
       }
       if(sceltaComputer=="Forbici" && sceltaGiocatore=="Carta")
       {
           punti_giocatore=punti_giocatore+0;
           punti_computer=punti_computer+1;
           cout << "Computer vince! " << endl << endl;                             
       }
    }
    
    int main(int argc, char *argv[])
    {
        char scelta='_';
    	string sceltaComputer,sceltaGiocatore;
    	srand (time(NULL));
    
    	cout << "Si cominicia il gioco: " << endl << endl;
         
         while(scelta!='f')
        {
           system("CLS");
           cout << "Premi il tasto: " << endl << endl;
           cout << "[1] - Sasso." << endl;                
           cout << "[2] - Carta." << endl;                
           cout << "[3] - Forbici." << endl;                
           cout << "[f] - Esci dal gioco." << endl;                
           cout << endl << "Scelta :" << endl << endl;                
           scelta=getch();
           switch(scelta)
           {
              case '1':
              {
                 sceltaComputer=jugada();
                 sceltaGiocatore="Sasso";
                 cout << "Il Giocatore ha scelto " <<  sceltaGiocatore << "." << endl <<endl;
                 cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;;
                 play(sceltaComputer,sceltaGiocatore);
                 cout << "Punti Giocatore: " << punti_giocatore << "   " << "Punti Computer: " << punti_computer << endl;                          
                 getch();            
                 break;
              }                           
              case '2':
              {  
                 sceltaComputer=jugada();
                 sceltaGiocatore="Carta";
                 cout << "Il Giocatore ha scelto " <<  sceltaGiocatore << "." << endl <<endl;
                 cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;
                 play(sceltaComputer,sceltaGiocatore);
                 cout << "Punti Giocatore: " << punti_giocatore << "   " << "Punti Computer: " << punti_computer << endl; 
                 getch();             
                 break;
              }                           
              case '3':
              {
                 sceltaComputer=jugada();
                 sceltaGiocatore="Forbici";
                 cout << "Il Giocatore ha scelto " <<  sceltaGiocatore << "." << endl <<endl;
                 cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;
                 play(sceltaComputer,sceltaGiocatore);
                 cout << "Punti Giocatore: " << punti_giocatore << "   " << "Punti Computer: " << punti_computer << endl; 
                 getch();             
                 break;
              }                           
           }              
        }   	
        
        system("CLS");
        cout << "Punteggio finale: " << endl << endl;
        cout << "Punti Giocatore: " << punti_giocatore << "   " << "Punti Computer: " << punti_computer << endl << endl; 
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2010
    Messaggi
    466
    Originariamente inviato da Rayan94
    Scusami se te lo dico ma stai imparando c++ da solo o ti insegna un cane?!
    Togli quella system.

  8. #8
    Peccato in questo grande forum che ci siano ragazzini che non hanno educazione

  9. #9
    Scusami se te lo dico ma stai imparando c++ da solo o ti insegna un cane?!
    Mi pare che quando hai avuto bisogno e hai postato la/le tua/tue domande tu abbia ricevuto risposta e che tu non sia stato offeso se ti mancava qualche conoscenza, credo che non sia il caso di permettersi di giudicare e offendere in questo modo gli altri.
    Salute a voi, da Laikius!

    --> Faber est suae quisque fortunae <--

  10. #10
    Utente di HTML.it
    Registrato dal
    Jan 2011
    Messaggi
    15
    okok chiedo scusa...siccome ora non mi fa editare lo tolgo dopo ^^ cmq non volevo offedere

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.