I'm currently trying to write a batch program that takes in two numbers that the user inputs. I had to create an exit number for the user if they choose to exit the program by entering the number 22. If the user doesn't exit the program it goes to check that the second number entered isn't 0. If it is 0 the user has to reenter another number and then proceed to divide the first number by the second number and display it.
My current issue is that if the user enters a correct value for both variables it still requests the user to another number for the secondNum. The program is supposed to continue running until the user enters the exit number 22. As for the display I don't want to only display the out put but rather this: 10 divided by 2 = 5.
@echo off
title lodiDpgm4
echo resulst.txt
echo Daniel Lodi >> results.txt
set datet=%date:~-7,2%-%date:~-10,2%-%date:~-4,4%
%time:~0,2%:%time:~3,2%:%time:~6,2%
echo %datet% >> results.txt
setlocal enabledelayedexpansion
:main
cls
set /p firstNum="Enter your first number"
if !firstNum! == 22 goto :eof
set /p secondNum="Enter your second number"
if !secondNum! == 22 goto :eof
if "%secondNum%"=="0" goto :loop
pause
:loop
set /p "secondNum=You can not divide by 0 please enter another number"
if "%secondNum%"=="0" goto :loop
pause
:calculate
@echo off
set /a results=(firstNum/secondNum)
echo %results%
pause
:eof
cls
@echo off
echo.
echo.
echo. Promgram has ended, thank you.
Aucun commentaire:
Enregistrer un commentaire