Ptis problemes
Résolu
nirv4v4
Messages postés
30
Statut
Membre
-
nirv4v4 Messages postés 30 Statut Membre -
nirv4v4 Messages postés 30 Statut Membre -
Bonjour,
je suis debutant (et amateur) en programmation et je recontres qques chti problemes :
-dans la création d'un jeu simple du style question reponses, quelque soit la reponses que je lui mets, il me repond NAN!! voici ma prog :
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 2
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
if (j = r) then
wscript.echo "BRAVO!!"
else
wscript.echo "NAAAAAAn !!"
-et un autre probleme : je ne sais pas comment lui dire de choisir une question au hazard dans les questions que je lui ai faites (creation stopée au bout de 2 pour reflechir a ces problemes...)
MERCI BEAUCOUP D'AVANCE
je suis debutant (et amateur) en programmation et je recontres qques chti problemes :
-dans la création d'un jeu simple du style question reponses, quelque soit la reponses que je lui mets, il me repond NAN!! voici ma prog :
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 2
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
if (j = r) then
wscript.echo "BRAVO!!"
else
wscript.echo "NAAAAAAn !!"
-et un autre probleme : je ne sais pas comment lui dire de choisir une question au hazard dans les questions que je lui ai faites (creation stopée au bout de 2 pour reflechir a ces problemes...)
MERCI BEAUCOUP D'AVANCE
Configuration: Windows XP Internet Explorer 7.0
16 réponses
-
au fait, je n'ai pas mis les questions dans le message ci dessus. Est-ce necessaire?
-
Salut,
alors pour la première partie il te faut convertir ta chaine j en entier avec la fonction CInt
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 2
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
j = CInt(j)
if (j = r) then
wscript.echo "BRAVO!!"
else
wscript.echo "NAAAAAAn !!"
Si ça ne fonctionne toujours pas converti "r" aussi en entier mais bon normalement il est déjà en entier si tu l'as déclaré plus haut.
Pourrais-tu être un peu plus clair sur les questions au hasard ?
-
je voudrai que les questions ne soient pas dans l'ordre ou je les ai rentrées
MERCIII -
oui mais maintenant il me dit
erreur ligne 14 CInt non compatible
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 5
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
j = CInt(j)
if (j = r) then
wscript.echo "BRAVO!!"
else
wscript.echo "NAAAAAAn !!"
' Q1
q1 = inputbox("combien font 6*5")
if q1 = 30 then
'wscript.echo "bonne reponse!!" : score=score+1
wscript.echo score & " point(s)"
else
wscript.echo "dommage!!" : score=score-1
wscript.echo score & "point(s)"
end if
' Q2
q2 = inputbox("q2")
q3 = inputbox("q3")
q4 = inputbox("q4")
q5 = inputbox("q5")
end if
next
merci -
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question -
ligne 14 c'est la ligne que tu ma fait rajouter :
j = CInt(j) -
et puis avec mes questions, je veux tout simplement qu'elles ne s' affiche pas dans l'orde Q1 Q2 Q3 ... mais que leur ordre soit aleatoire
-
oula il me trouve de plus en plus d'erreurs sans que je n'ai modifié le .vbs entre temps!!!
-
-
Voici mon code ça fonctionne parfaitement
wscript.echo "salut!!!" sava = inputbox("ça va?") wscript.echo "OK cool, c'est parti!!" score = 0 wscript.echo "score : 0" for i = 1 to 2 randomize a = CInt(Int((10 * Rnd()) + 1)) b = CInt(Int((10 * Rnd()) + 1)) j = inputbox ("combien font " & a & " fois " & b & " ?") r = a*b msgbox "ta reponse: " & j & " réponse : " & r j = CInt(j) if (j = r) then wscript.echo "BRAVO!!" else wscript.echo "NAAAAAAn !!" End if Next
-
-
Merci beaucoup!!!! ça marche a merveille mais (desolé de t'emmerder si longtemps) est-ce que tu sais comment faire un inputbox qui demande si on veut reprendre le score de la derniere fois ou non. je sais pas si c'est juste :
r2 = inputbox("Veux-tu remettre ton score a 0?")
if r2 = oui then
score = 0
else
...(je ne sais pas quoi mettre pour lui dire de reprendre le score qu'on avait avant de quitter....)-
En fait ce que tu veux c'est que lorsque tu fermes et que tu réouvres ton application il te demande si tu veux recommencer avec l'ancien score ? Pour reprendre le score de la dernière fois il faudrait déjà que tu puisses sauvegarder ce score.
Tu peux par exemple stocker ton dernier score dans un fichier texte et ensuite le récupérer à la prochaine ouverture.
-
-
-
pour les questions au hazard , j'ai trouvé :
for i = 1 to 3
randomize
a = CInt(Int((5 * Rnd()) + 1))
select case (a)
case 1:
msgbox "question 1"
case 2:
msgbox "q2"
case 3:
msgbox "q3"
case 4:
msgbox "q4"
case else
msgbox "q5"
end select
next-
Bon déjà il te faut un fichier "score.txt" à coté de ton fichier vbs
En suite tu utilises ce code
wscript.echo "salut!!!" r2 = inputbox("Veux-tu remettre ton score a 0?") if r2 = "oui" then score = 0 else 'On récupère le score Dim oFso, f Set oFso = CreateObject("Scripting.FileSystemObject") Set f = oFso.OpenTextFile("score.txt", 1) while Not f.AtEndOfStream score = CInt(f.ReadLine) Wend f.Close End if wscript.echo "Ton score est " & score for i = 1 to 2 randomize a = CInt(Int((10 * Rnd()) + 1)) b = CInt(Int((10 * Rnd()) + 1)) j = inputbox ("combien font " & a & " fois " & b & " ?") r = a*b msgbox "ta reponse: " & j & " réponse : " & r j = CInt(j) if (j = r) then wscript.echo "BRAVO!!" score = score + 1 else wscript.echo "NAAAAAAn !!" if score > 0 then score = score - 1 End if End if Next wscript.echo "Ton score final est " & score r2 = inputbox("Veux-tu sauvegarder ton score?") if r2 = "oui" then 'On sauvegarde le score Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("score.txt", ForWriting,true) f.write(score) f.Close End if
Allez ++
-
-
merci beaucoup!! au fait, sait tu comment quitter le jeu quand on veut en entrant une reponse speciale?
-
mais je doi mettre quoi dans le script a la place de :
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 2
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
j = CInt(j)
if (j = r) then
wscript.echo "BRAVO!!" : score=score+1
wscript.echo "tu as " & score & " point(s)"
else
wscript.echo "NAAAAAAN !!" : score=score-1
wscript.echo "tu as " & score & " point(s)"
End if
Next-
Tappe "stop" lors d'une question et ça va quitter
wscript.echo "salut!!!"
sava = inputbox("ça va?")
wscript.echo "OK cool, c'est parti!!"
score = 0
wscript.echo "score : 0"
for i = 1 to 2
randomize
a = CInt(Int((10 * Rnd()) + 1))
b = CInt(Int((10 * Rnd()) + 1))
j = inputbox ("combien font " & a & " fois " & b & " ?")
If j = "stop" then
Exit
End if
r = a*b
msgbox "ta reponse: " & j & " réponse : " & r
j = CInt(j)
if (j = r) then
wscript.echo "BRAVO!!" : score=score+1
wscript.echo "tu as " & score & " point(s)"
else
wscript.echo "NAAAAAAN !!" : score=score-1
wscript.echo "tu as " & score & " point(s)"
End if
Next
-
-
oui mais si je mets score = 0, il va remettre le score a 0 :(
-
-