user2763322
user2763322

Reputation: 1

Dos Goto command skip

I wrote this program to convert fractions to percent but my goto commands are being skipped. It goes through the program and skips the if statements. Here is the code:

@echo off

:menu
Echo Fraction to Percent=1
Echo Percent to Fraction =2
set /p choice =Enter the number of your choice:
if choice == 1 goto ftp
if choice == 2 goto ptf
if choice == 3 Exit

:ptf
pause

:ftp
set /p tn= Enter the top number:
set /p bn= Enter the Bottom number:
set /a mtn= %tn% * 100
set /a cf= %mtn% / %bn%
set /a cf2= %cf% * 10000
set /a mtn3= %tn% * 1000000
set /a cf3= %mtn3% / %bn%
set /a cf4= %cf3% - %cf2%
set /a cf5= %cf2% / 10000
echo %cf5%.%cf4%
goto continue


:continue
set /p con =Continue? (y/n):
if con ==y goto ftp 
if con ==n goto menu

Upvotes: 0

Views: 2031

Answers (1)

Joe DF
Joe DF

Reputation: 5548

The problem

on this line: set /p choice =Enter the number of your choice:
choice is a var so therefore it should be reference as a var like so
%choice% instead of choice so as an if i suggest doing...
if "%choice%"=="1" goto ftp

Tips


Try adding quotes like On the wikipedia (batch file) page Example
if "%choice%"=="1" goto shutdown
Also see more info on if-statements here: http://www.robvanderwoude.com/if.php

Upvotes: 1

Related Questions