09/10/12 20:50
Ho lavorato un pò e penso di essere arrivato ad una buona versione del programma, cosa ne pensate?
(non ho usato gli ultimi preziosi consigli di goblin perchè volevo vedere se riuscivo a finire tutto da solo)
(non ho usato gli ultimi preziosi consigli di goblin perchè volevo vedere se riuscivo a finire tutto da solo)
program estrazione_lotto; uses crt; type tabella = array[1..11,1..5] of integer; nomi = array[1..11] of string[12]; const nomi_ruote : nomi = ('Nazionale', 'Bari','Cagliari', 'Firenze','Genova','Milano','Napoli','Palermo','Roma','Torino','Venezia'); var tab:tabella; numa,numb,numc,ruota,band:integer; inizio:string; tipo:char; procedure centra(scritta:string;y:integer); var x:integer; begin x:=((80-(length(scritta)))div 2); gotoxy(x,y); write(scritta); end; procedure estrazione; var a,b,pos,x,i,j: integer; begin randomize; for a:=1 to 11 do begin tab[a,1]:=random(90)+1; for b:=2 to 5 do begin repeat x:=random(90)+1; pos:=1; while (tab[a,pos]<>x) and (pos < b) do pos:=pos+1; until (pos>=b); tab[a,b]:=x end; end; end; procedure scrivi; var a,b,num,col:integer; numa:string; begin centra('Estrazione del lotto',1); num:=2; col:=5; (* gotoxy(1,5);*) for a:=1 to 11 do begin gotoxy(num,col); write (nomi_ruote[a]:9); Write(' '); for b:=1 to 5 do begin write (tab[a,b]:5); end; col:=col+1; end; end; procedure cerca; var a,b,cont,num:integer; begin gotoxy(2,20); Write('Cerca un Numero: '); readln(num); cont:=0; for a:=1 to 11 do for b:=1 to 5 do if num=tab[a,b] then begin Writeln(' Il numero si trova nella ruota numero ',a,' in posizione ', b,''); cont:=1; end; If cont=0 then writeln(' Il numero non e'' presente in nessuna ruota'); end; procedure gioca; var terno:string; b,a:integer; begin writeln; Writeln; Writeln; write(' Vuole fare una puntata(si\no)? '); readln(inizio); if inizio=('si') then begin write(' Vuole giocare un ambo o un terno? '); readln(tipo); case tipo of 'a' : begin Write(' Inserisci il primo numero che vuoi puntare: '); readln(numa); Write(' Inserisci il secondo numero che vuoi puntare: '); readln(numb); gotoxy(2,10); writeln('1 = Nazionale'); Writeln(' 2 = Bari'); Writeln(' 3 = Caglairi'); Writeln(' 4 = Firenze'); Writeln(' 5 = Genova'); Writeln(' 6 = Milano'); Writeln(' 7 = Napoli'); Writeln(' 8 = Palermo'); Writeln(' 9 = Roma'); writeln(' 10 = Tornino'); Writeln(' 11 = Venezia'); gotoxy(1,8); Write(' Inserisci il nome (numero da 1 a 11) della ruota in cui vuoi giocare: '); readln(ruota); band:=0; a:=ruota; for b:=1 to 5 do begin if (numa=tab[a,b]) then band:=band+1; if (numb=tab[a,b]) then band:=band+1; end; if band>=2 then begin if numa<>numb then begin clrscr; textcolor(green); centra(' Congratulazioni, hai vinto!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end else if numa=numb then begin clrscr; Textcolor(red); centra('Non puoi puntare due numeri uguali!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; If band<2 then begin if numa<>numb then begin clrscr; Textcolor(red); centra('Hai perso!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end else if numa=numb then begin clrscr; Textcolor(red); centra('Non puoi puntare due numeri uguali!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end; 't': begin Write(' Inserisci il primo numero che vuoi puntare: '); readln(numa); Write(' Inserisci il secondo numero che vuoi puntare: '); readln(numb); Write(' Inserisci il terzo numero che vuoi puntare: '); readln(numc); gotoxy(2,10); writeln('1 = Nazionale'); Writeln(' 2 = Bari'); Writeln(' 3 = Caglairi'); Writeln(' 4 = Firenze'); Writeln(' 5 = Genova'); Writeln(' 6 = Milano'); Writeln(' 7 = Napoli'); Writeln(' 8 = Palermo'); Writeln(' 9 = Roma'); writeln(' 10 = Tornino'); Writeln(' 11 = Venezia'); gotoxy(1,8); Write(' Inserisci il nome(numero) della ruota in cui vuoi giocare: '); readln(ruota); band:=0; a:=ruota; for b:=1 to 5 do begin if (numa=tab[a,b]) then band:=band+1; if (numb=tab[a,b]) then band:=band+1; if (numc=tab[a,b]) then band:=band+1; end; if band=3 then begin if (numa<>numb) and (numa<>numc) then begin clrscr; textcolor(green); centra(' Congratulazioni, hai vinto!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end else if (numa=numb) or (numc=numa) or (numb=numc) then begin clrscr; Textcolor(red); centra('Non puoi puntare numeri uguali!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; If band<3 then begin if (numa<>numb) and (numb<>numc) then begin clrscr; Textcolor(red); centra('Hai perso!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end else if (numa=numb) or (numb=numc) or (numa=numc) then begin clrscr; Textcolor(red); centra('Non puoi puntare numeri uguali!',11); centra('A breve ti verra'' visualizzata l''estrazione completa',13); gotoxy(2,19); end; end; end; end; if inizio=('no') then write(' Attenda, caricamento estrazione in corso....'); end; procedure tuoi_dati; begin gotoxy(2,17); if inizio <> ('no') then if tipo = ('a') then begin writeln('I numeri che avevi puntatno sono: ',numa,' e ',numb); Writeln(' Hai puntato nella ruota numero ',ruota); end else if tipo = ('t') then begin writeln('I numeri che avevi puntatno sono: ',numa,', ',numb,' e ',numc); Writeln(' Hai puntato nella ruota numero ',ruota); end; end; var scelta:string; begin repeat clrscr; estrazione; centra('Estrazione del lotto',1); gioca; delay(4000); textcolor(7); clrscr; scrivi; (*cerca;*) writeln; Writeln; tuoi_dati; textcolor(7); Writeln; Write(' Vuoi continuare?(si\no) '); readln(scelta); until scelta='no' end.