TO DO: DISPLAY ALL NUMBERS INPUTED, APPEND NUMBERS UNTO RESULTS.TXT FILE Call th
ID: 3916715 • Letter: T
Question
TO DO: DISPLAY ALL NUMBERS INPUTED, APPEND NUMBERS UNTO RESULTS.TXT FILE
Call this program program1.bat
- Implement mod (find the remainder), with error trapping, using if
and while commands,
How:
- Append your name, current date and time to a NEW file called
results.txt
- Use a simulated while loop.
- If the user enters the value 999 for the first or the second number,
you must
exit the while loop immediately.
- Ask the user to enter the first number. If it is 999, exit
immediately.
- Ask the user to enter the second number. If it is 999, exit
immediately.
- If the second number is ZERO inform the user and ask for a correct
second number.
- If the second number is NOT a zero, do the operation, display all
numbers in this computation using labels, and append them to the
results.txt file.
I ALREADY HAVE THIS CODE
@echo off
:loop
set /p name= "Please enter your name: "
set mydate=%date%
set mytime=%time%
echo %name% %mydate% %mytime% >> "result.txt"
set /p a= "Enter 1st number: "
if %a% equ 999 (goto:eof) else (goto:promptb)
:promptb
set /p b= "Enter 2nd number: "
if %b% equ 999 (goto:eof) else ( if %b% equ 0 (goto:promptb))
:calculate
set /a c= %a% %% %b%
echo %c%
goto loop
pause
Explanation / Answer
@ echo off
setlocal enabledelayedexpansion
echo results.txt
echo Roberto Martinez >> results.txt
set dt=%date:~7,2%-%date:~4,2%-%date:~10,4%_%time:~0,2%_%time:~3,2%_%time:~6,2%
echo %dt% >> results.txt
goto :main
:main
setlocal
set /p choice1="Enter your first number"
set /p choice2="Enter your second number"
if !choice1! == 55 goto :eof
if !choice2! == 0 goto :eof
:loop
goto :loop
echo.
echoo ^^
endlocal
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.