Write a batch file that
would input a users choice based on the table below:
|
Choice
|
Input the following
|
Compute & Output
|
|
“C” for Circle
|
Radius of a
Circle
|
Area = pr2
|
|
“S” for Square
|
Side of Square
|
Area = s2
|
|
“R” for
Rectangle
|
Length &
Width of a Rectangle
|
Area = lw
|
|
“T” for
Triangle
|
Base &
Height of a Triangle
|
Area = 1/2 bh
|
Code:
@echo off
:top
echo Select a Letter Below:
echo c for Circle
echo s for Square
echo r for Rectangle
echo t for Triangle
echo -------------------------
set /p input=Input:
if %input%==c (
goto :c
) else if %input%==s (
goto :s
) else if %input%==r (
goto :r
) else if %input%==t (
goto :t
) else (
echo Invalid Input. Please select again.
pause
cls
goto :top
)
:c
set /p radius=Radius:
set pi=314/100
set /a area=%radius%*%radius%*%pi%
echo Area = %area%
pause
cls
goto :top
:s
set /p side=Side:
set /a area=%side%*%side%
echo Area = %area%
pause
cls
goto :top
:r
set /p length=Length:
set /p width=Width:
set /a area=%length%*%width%
echo Area: %area%
pause
cls
goto :top
:t
set /p base=Base:
set /p height=Height:
set /a area=%base%*%height%
set /a area=%area%/2
echo Area: %area%
pause
cls
goto :top
------------------------------------------------------------------------------------------------------------
Write a batch file that would input a course code and output its
equivalent course;
Input => Course Code Output
=> Course
A or a “Accounting”
B or b “Banking and Finance”
C or c “Computer Science”
D or d “Dentistry”
E or e “Engineering”
else “Invalid Course Code”
Code:@echo off
:top
set /p course=Course Code:
IF %course%==a (
echo "Accounting"
pause
cls
goto :top
) ELSE IF %course%==A (
echo "Accounting"
pause
cls
goto :top
) ELSE IF %course%==b (
echo "Banking and Finance"
pause
cls
goto :top
) ELSE IF %course%==B (
echo "Banking and Finance"
pause
cls
goto :top
) ELSE IF %course%==c (
echo "Computer Science
pause
cls
goto :top
) ELSE IF %course%==C (
echo "Computer Science
pause
cls
goto :top
) ELSE IF %course%==d (
echo "Dentistry"
pause
cls
goto :top
) ELSE IF %course%==D (
echo "Dentistry"
pause
cls
goto :top
) ELSE IF %course%==e (
echo "Engineering"
pause
cls
goto :top
) ELSE IF %course%==E (
echo "Engineering"
pause
cls
goto :top
) ELSE (
echo "Invalid Course Code"
pause
cls
goto :top
)
------------------------------------------------------------------------------------------------------------
Write a batch file that would input a year code and output year
level.
Input => Year Code Output
=> Year Level
1 “First Year” next line “Freshmen”
2 “Second
Year” next line “Sophomore”
3 “Third
Year” next line “Junior”
4 “Fourth
Year” next line “Senior”
Code:
@echo off
:top
set /p year=Year Code:
echo Year Level:
IF %year%==1 (
echo First Year
echo "Freshmen"
pause
cls
goto :top
) ELSE IF %year%==2 (
echo Second Year
echo "Sophomore"
pause
cls
goto :top
) ELSE IF %year%==3 (
echo Third Year
echo "Junior"
pause
cls
goto :top
) ELSE IF %year%==4 (
echo Fourth Year
echo "Senior"
pause
cls
goto :top
) ELSE (
echo "Invalid Year Code"
pause
cls
goto :top
)
Your code is flawed. Batch files cannot do floating point match. So dividing 314 by 100 will just give you 3.
ReplyDeleteYour code is flawed. Batch files cannot do floating point match. So dividing 314 by 100 will just give you 3.
ReplyDelete