Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - affari tuoi
Forum - C/C++ - affari tuoi - Pagina 2

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
oretovalley (Normal User)
Pro


Messaggi: 109
Iscritto: 12/04/2009

Segnala al moderatore
Postato alle 18:59
Venerdė, 22/01/2010
Allora, ho deciso di sistemarti l'algoritmo, e tutto il codice, che tutto sembrava, piuttosto che codice in C, visto che usavi, le librerie del C++ e del C, costrutti del C++, e costrutti del C, ti ho sistemato l'intero codice, adesso č tutto in C++, il tuo errore e stato fixato, l'intero codice č stato ottimizzato :)

Codice sorgente - presumibilmente C++

  1. #include<iostream>
  2. #include<ctime>
  3. #define num_pacchi 20
  4. using namespace std;
  5.  
  6. int Gioca(string nome, int pacco);      
  7. int offerta(string nome, int pacco);                  
  8. int Apertura_Pacco();                            
  9. int Fine();                            
  10.  
  11. char nome[20];
  12. int pacco,fare_offerta= 0;                      
  13. int pacchi_rimanenti[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
  14.  
  15. struct pa
  16. {
  17.   int tipo;
  18.   int contenuto_pacco;                 //{Pacchi}
  19.   string premio;
  20. }p[num_pacchi];
  21.  
  22.  
  23. int cambio_finito=0;
  24. int main () {
  25.    
  26.     system("color 34");
  27.     srand(time(NULL));
  28.     int scelta;
  29.    
  30.     p[0].tipo=2;
  31.     p[0].contenuto_pacco=-1;
  32.     p[0].premio="aaaaaa";
  33.     p[1].tipo=2;
  34.     p[1].contenuto_pacco=-1;
  35.     p[1].premio="bbbbb";
  36.     p[2].tipo=2;
  37.     p[2].contenuto_pacco=-1;
  38.     p[2].premio="ccccc";
  39.     p[3].tipo=2;
  40.     p[3].contenuto_pacco=-1;
  41.     p[3].premio="ddddd";
  42.     p[4].tipo=2;
  43.     p[4].contenuto_pacco=-1;
  44.     p[4].premio="eeeee";
  45.     p[5].tipo=1;
  46.     p[5].contenuto_pacco=1;
  47.     p[5].premio="1 euro";
  48.     p[6].tipo=1;
  49.     p[6].contenuto_pacco=5;
  50.     p[6].premio="5 euro";
  51.     p[7].tipo=1;
  52.     p[7].contenuto_pacco=10;
  53.     p[7].premio="10 euro";
  54.     p[8].tipo=1;
  55.     p[8].contenuto_pacco=20;
  56.     p[8].premio="20 euro";
  57.     p[9].tipo=1;
  58.     p[9].contenuto_pacco=100;
  59.     p[9].premio="100 euro";
  60.     p[10].tipo=1;
  61.     p[10].contenuto_pacco=500;
  62.     p[10].premio="500 euro";
  63.     p[11].tipo=1;
  64.     p[11].contenuto_pacco=1000;
  65.     p[11].premio="1000 euro";
  66.     p[12].tipo=1;
  67.     p[12].contenuto_pacco=5000;
  68.     p[12].premio="5000 euro";
  69.     p[13].tipo=1;
  70.     p[13].contenuto_pacco=10000;
  71.     p[13].premio="10000 euro";
  72.     p[14].tipo=1;
  73.     p[14].contenuto_pacco=20000;
  74.     p[14].premio="20000 euro";
  75.     p[15].tipo=1;
  76.     p[15].contenuto_pacco=50000;
  77.     p[15].premio="50000 euro";
  78.     p[16].tipo=1;
  79.     p[16].contenuto_pacco=75000;
  80.     p[16].premio="75000 euro";
  81.     p[17].tipo=1;
  82.     p[17].contenuto_pacco=100000;
  83.     p[17].premio="100000 euro";
  84.     p[18].tipo=1;
  85.     p[18].contenuto_pacco=250000;
  86.     p[18].premio="250000 euro";
  87.     p[19].tipo=1;
  88.     p[19].contenuto_pacco=500000;
  89.     p[19].premio="500000 euro";    
  90.    
  91.    do {
  92.         system("cls");
  93.         cout << "\t\t****************************************************\n";
  94.         cout << "\t\t*                                                  *\n";
  95.         cout << "\t\t*            Benvenuti ad AFFARI TUOI              *\n";
  96.         cout << "\t\t*                                                  *\n";
  97.         cout << "\t\t****************************************************\n\n";
  98.         cout << "1 - Gioca\n\n2 - Esci\n\n";
  99.         cin >> scelta;      
  100.    }while(scelta < 1 || scelta > 2);    
  101.      
  102.     switch (scelta) {
  103.            
  104.        case 1:
  105.             system("cls");
  106.             cout << "\n\nInserisci il tuo nome: ";
  107.             cin >> nome;
  108.             while (pacco < 1 || pacco > 20)
  109.             {
  110.               cout << "\n\nInserisci il numero del pacco che vuoi(1-20): ";
  111.               cin >> pacco;
  112.             }
  113.             Gioca(nome,pacco);              
  114.             break;
  115.        case 2:
  116.             exit (1);
  117.             }        
  118. }
  119.  
  120. int Gioca(string nome, int pacco) {//fare_offerta++;
  121.      
  122.     Fine();
  123.      
  124.     if (fare_offerta > 0 && fare_offerta == 3)
  125.                 offerta(nome, pacco);
  126.      
  127.     int chiama = 0;        //Chiamata Pacco    
  128.        
  129.         do {
  130.        
  131.                 system("cls");
  132.                 cout <<  "Pacchi rimasti: ";           
  133.                 for (int x = 0; x < 20; x++) {          //Mostra Pacchi Rimasti
  134.                         if (pacchi_rimanenti[x]!=pacchi_rimanenti[pacco-1] && pacchi_rimanenti[x]!=0)
  135.                                 cout << pacchi_rimanenti[x] << " ";              
  136.                         else
  137.                                 cout << " ";            
  138.                 }
  139.                          
  140.                 for (int y = 0; y < num_pacchi; y++) {  //Mostra Valori Rimasti          
  141.                         if(p[y].contenuto_pacco!=0)
  142.                                 cout << endl << p[y].premio;
  143.                         else
  144.                                 cout << endl;                                    
  145.                 }
  146.                
  147.                 cout << endl << endl << endl;
  148.                 cout << "Quale pacco vuoi chiamare? ";
  149.                 cin >> chiama;         
  150.         }while(pacco == chiama || pacchi_rimanenti[chiama-1]==0);      
  151.        
  152.         Apertura_Pacco();
  153.         pacchi_rimanenti[chiama-1]=0;
  154.         fare_offerta++;        
  155.         getchar();    
  156.         Gioca(nome, pacco);
  157. }
  158.  
  159. int offerta(string nome, int pacco) {
  160.        
  161.     int tipo_offerta = rand()%2;;        
  162.     int scelta = 0;
  163.      
  164.     if (tipo_offerta==0) {
  165.                          
  166.         int tot_pacchi_rimasti = 0;                  //TOTale PaCchi
  167.         int valore_pacchi_rimasti = 0;             //TOTale RiManente
  168.         int off = 0;
  169.        
  170.                 for (int x=0; x < 20; x++) {
  171.                         if ((p[x].contenuto_pacco!=0) && (p[x].contenuto_pacco==-1))                           
  172.                                 tot_pacchi_rimasti++;
  173.                         else if (p[x].contenuto_pacco!=0) {                      
  174.                                 valore_pacchi_rimasti += p[x].contenuto_pacco;
  175.                                 tot_pacchi_rimasti++;                    
  176.                         }          
  177.                 }
  178.                
  179.                 system("cls");
  180.                 off = ((valore_pacchi_rimasti / tot_pacchi_rimasti)) * 0.1;                                            
  181.                                                
  182.                 do {
  183.             cout << nome << ", per te l'offerta e': " << off;
  184.                         cout << endl << "Accetti l'offerta? (1)-(SI) - (0)-(NO)" << endl;
  185.                         cin >> scelta;
  186.                 }while(scelta < 0 || scelta > 1);                      
  187.                        
  188.                 if (scelta==1) {
  189.                         system("cls");
  190.                         cout << "Hai vinto: " << off << endl;
  191.                         system("pause");
  192.                         exit(1);               
  193.                 }
  194.        
  195.         } else {  
  196.                                        
  197.                 do {
  198.                         system("cls");
  199.                         cout << "Vuoi cambiare pacco? 1-Si 0-No" << endl;
  200.                         cin >> scelta;
  201.         }while (scelta> 1 || scelta< 0);              
  202.          
  203.         if (scelta==1) {               
  204.                         cout << endl << "Con quale pacco vuoi cambiare il tuo?" << endl << "Nuovo pacco: ";
  205.                         cin >> pacco;
  206.                 }
  207.         }
  208.         fare_offerta = 0;
  209.     Gioca(nome,pacco);                                
  210. }    
  211.  
  212. int Apertura_Pacco() {    
  213.     int PcVal;
  214.     system("cls");
  215.     cout << "Il valore del pacco e': ";
  216.     PcVal = rand() % 20;      
  217.         while (p[PcVal].contenuto_pacco==0)
  218.                 PcVal = rand() % 20;
  219.                
  220.     cout << p[PcVal].premio;
  221.     p[PcVal].contenuto_pacco=0;
  222.         getchar();
  223. }
  224.  
  225. int Fine() {
  226.     string TotWin;
  227.     int temp,flag=1;
  228.          //Totale Vincita
  229.     if (fare_offerta==19) {
  230.                 system("cls");
  231.                 for (int y = 0; y < 20; y++) { //Trova Valore che hai vinto
  232.                         if (p[y].contenuto_pacco!=0) {
  233.                                 if (p[y].contenuto_pacco!=-1)
  234.                                         TotWin =p[y].premio;          
  235.                                 else {
  236.                                         flag=0;
  237.                                         temp=y;  
  238.                                 }
  239.                         }
  240.                 }
  241.                 if(flag)
  242.                         cout << "Hai vinto: " << TotWin << "!!!\n\n";
  243.                 else
  244.                         cout << "Hai vinto: " << p[temp].premio << "\n\n";
  245.                
  246.                 system("pause");
  247.                 exit (1);
  248.         }
  249. }



PM Quote
Avatar
NickoMaiden (Normal User)
Pro


Messaggi: 115
Iscritto: 10/06/2009

Segnala al moderatore
Postato alle 22:06
Venerdė, 22/01/2010
Testo quotato

Postato originariamente da Anonymous:

scusate per l'enorme OT che sto facendo, ma mi sembrava doveroso un bel LOL dopo aver letto la firma di NickoMaiden

Codice sorgente - presumibilmente C/C++

  1. char segreto[100]={"Abaca da cala da ciaccia"};
  2. for(int i=0;i<100;i++)
  3.   {
  4.   if(segreto[ i ]=='a'||segreto[ i ]=='A')
  5.     {
  6.     segreto[ i ]='u';
  7.     }
  8.   }
  9. cout<<segreto;
  10. system("pause");
  11. return EXIT_SUCCESS;





ot
xD sono contento che sia di gradimento
fine ot

PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo