Batch File Help

I need help knowing why this doesnt work

Page 1 of 1

4 Replies - 1288 Views - Last Post: 28 August 2009 - 08:17 PM Rate Topic: -----

#1 C++ Programmer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 20
  • View blog
  • Posts: 548
  • Joined: 12-June 08

Batch File Help

Post icon  Posted 22 December 2008 - 12:56 PM

Ok, i know the code isnt finished...but i didnt want to go any farther until i fixed this problem. Here is the code, the problem is that no matter what you type in for the answer if you want to play the game or not it just exits automatically.

@echo off
:start
cls
title Play Game?
echo Would you like to play the random quiz?
set /p input=Answer 
set input=
if %input% == "dhfghd" goto invalid
if %input% == "yes" goto question1
if %input% == "Yes" goto question1
if %input% == "YES" goto question1
if %input% == "no" goto answerno
if %input% == "No" goto answerno
if %input% == "NO" goto answerno

:invalid
cls
title Invalid
echo I am sorry, that is not valid.
echo I will restart you at the beginning.
pause
goto start

:answerno
cls
title I'm Sorry
echo Ok, well maybe next time.
pause
goto exit

:question1
cls
title Question 1
echo What was the name of our first president?
echo TIP: Please put only the letter.
echo TIP: Always have caps lock on.
echo ------------------------------------------
echo A. Lincoln
echo ------------------------------------------
echo B. Washington
echo ------------------------------------------
echo C. Your Mom
echo ------------------------------------------
set /p input=Answer 
set input=
if %input% == "A" goto wronganswer1
if %input% == "a" goto wronganswer1
if %input% == "B" goto question2
if %input% == "b" goto question2
if %input% == "C" goto wronganswer1
if %input% == "c" goto wronganswer1

:wronganswer1
cls
title Wrong Answer!
echo You got Question 1 wrong.
echo Please try again.
pause
goto question1

:question2
cls
title Question 2


if someone could help me with this i would be very grateful

Thanks in advance
- C++ Programmer
:D MERRY CHRISTMAS :D

Is This A Good Question/Topic? 0
  • +

Replies To: Batch File Help

#2 Vomster  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 198
  • Joined: 15-May 08

Re: Batch File Help

Posted 22 December 2008 - 01:06 PM

I put quotes around the input variable here
if "%input%" == "dhfghd" goto invalid
if "%input%" == "yes" goto question1
if "%input%" == "Yes" goto question1
if "%input%" == "YES" goto question1
if "%input%" == "no" goto answerno
if "%input%" == "No" goto answerno
if "%input%" == "NO" goto answerno


and here
if "%input%" == "A" goto wronganswer1
if "%input%" == "a" goto wronganswer1
if "%input%" == "B" goto question2
if "%input%" == "b" goto question2
if "%input%" == "C" goto wronganswer1
if "%input%" == "c" goto wronganswer1


This post has been edited by Vomster: 22 December 2008 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#3 C++ Programmer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 20
  • View blog
  • Posts: 548
  • Joined: 12-June 08

Re: Batch File Help

Posted 22 December 2008 - 05:55 PM

yeah, ill try that but i never used to have to do tat.
Was This Post Helpful? 0
  • +
  • -

#4 xxxAviaxxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 02-July 09

Re: Batch File Help

Posted 27 July 2009 - 11:18 AM

Try this:


@echo off
Title Quiz game!!!
:start
cls
title Play Game?
set /p input=Would you like to play the random quiz?
if %input% == y (goto question1)
if %input% == n (goto answerno) else (goto invalid)

:invalid
cls
echo I am sorry, that is not valid.
echo Please type in "y" or "n"
pause
goto start

:answerno
cls
echo Ok, well maybe next time.
pause
goto exit

:question1
cls
echo What was the name of our first president?
echo TIP: Please put only the letter.
echo TIP: Always have caps lock on.
echo ------------------------------------------
echo A. Lincoln
echo ------------------------------------------
echo B. Washington
echo ------------------------------------------
echo C. Your Mom
echo ------------------------------------------
set /p input=Answer 
set input=
if %input% == A (goto wronganswer1)
if %input% == B (goto question2)
if %input% == C (goto wronganswer1)

:wronganswer1
cls
echo You got Question 1 wrong.
echo Please try again.
pause
goto question1

:question2
cls


Was This Post Helpful? 0
  • +
  • -

#5 Yaroslav94  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 294
  • Joined: 15-July 09

Re: Batch File Help

Posted 28 August 2009 - 08:17 PM

If I HELPED thank ME!

Try deleting second input at top!

Luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1