Précédent   Forum du club des développeurs et IT Pro > Autres langages > Pascal > Langage
Langage Vos questions sur langage Pascal en général, ses évolutions, les technologies, ...
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 22/11/2012, 15h22   #1
hatenuke
Invité de passage
 
Homme
Étudiant
Inscription : octobre 2012
Messages : 4
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Étudiant
Secteur : Enseignement

Informations forums :
Inscription : octobre 2012
Messages : 4
Points : 0
Points : 0
Par défaut Utilisation de random

Bonjour et merci à ceux qui vont prendre la peine et le temps de bien vouloir lire mon post^^
Voilà, dans le cadre d'un exercice je dois refaire Le Compte est bon.
J'ai commencé a faire du code et j'obtiens :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//le compte est bon
// On dispose de 6 nombres ou chiffres tirés au hasard parmi :
//    les 9 premiers chiffres (1, 2, 3, 4, 5, 6, 7, 8, 9)
//    les nombres : 10, 25, 50, 100
//On tire au hasard un nombre compris entre 100 et 999.
 
const tb1=13;
const tb2=6;
var table: array [1..tb1] of integer;
var table2: array [1..tb2] of integer;
var x:integer;
 
 
begin
randomize;
table[1]:=1;
table[2]:=2;
table[3]:=3;
table[4]:=4;
table[5]:=5;
table[6]:=6;
table[7]:=7;
table[8]:=8;
table[9]:=9;
table[10]:=10;
table[11]:=25;
table[12]:=50;
table[13]:=100;
 
table2[1]:=random(table[1..13]);
table2[2]:=random(table[1..13]);
table2[3]:=random(table[1..13]);
table2[4]:=random(table[1..13]);
table2[5]:=random(table[1..13]);
table2[6]:=random(table[1..13]);
writeln(table2[1]);
writeln(table2[2]);
writeln(table2[3]);
writeln(table2[4]);
writeln(table2[5]);
writeln(table2[6]);
readln;
 
end.
Le problème est que quand j'écris table2[x]:=random(table[1..13]); j'obtiens une erreur
Citation:
Fatal: Syntax error, ] expected but .. found
Edit : la seule alternative que j'ai trouvé est de faire
Code :
1
2
3
4
5
repeat
randomize;
a:=random(100);
 
until a in [1,2,3,4,5,6,7,8,9,10,25,50,100];
mais bon c'est un peu lourd et moche :/
Merci^^
hatenuke est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2012, 17h02   #2
droggo
Expert Confirmé
 
Inscription : août 2006
Messages : 3 413
Détails du profil
Informations forums :
Inscription : août 2006
Messages : 3 413
Points : 3 768
Points : 3 768
Cie,

Révise la déclaration de la fonction random.
__________________
Il court en ce moment une espèce de grippe, mais elle ne court pas très vite, car on peut l'attraper sans courir.
droggo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/11/2012, 17h07   #3
Roland Chastain
Membre Expert
 
Homme Roland Chastain
Inscription : décembre 2011
Messages : 683
Détails du profil
Informations personnelles :
Nom : Homme Roland Chastain
Âge : 39
Localisation : Mali

Informations professionnelles :
Secteur : Enseignement

Informations forums :
Inscription : décembre 2011
Messages : 683
Points : 1 001
Points : 1 001
Essaie plutôt de faire comme ça :

Code :
table2[1]:=table[Random(tb1)+1];
__________________
L'Art est long et le Temps est court.
Roland Chastain est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 22/11/2012, 17h20   #4
hatenuke
Invité de passage
 
Homme
Étudiant
Inscription : octobre 2012
Messages : 4
Détails du profil
Informations personnelles :
Sexe : Homme

Informations professionnelles :
Activité : Étudiant
Secteur : Enseignement

Informations forums :
Inscription : octobre 2012
Messages : 4
Points : 0
Points : 0
Citation:
Envoyé par Roland Chastain Voir le message
Essaie plutôt de faire comme ça :

Code :
table2[1]:=table[Random(tb1)+1];
effectivement ca marche très bien ^^ merci beaucoup !
hatenuke est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 20h34.


 
 
 
 
Partenaires

Hébergement Web