Windows shell script help

coopermckay

Member
Oct 29, 2005
87
0
0
I am trying to write a windows shell script to calculate student grades for my class
and i am having trouble, I can get it to display the letter grades but not the grades
as numbers, I need to display both. The file is l7-grades.bat and when you run it you have to type a studentid number and then the grade, and it is supposed to show your student id number, grade as a number, and grade as a letter. For for example l7-grades.bat 1234 90 is supposed to show 1234 as your student id number 90 as your number grade and an A as your letter grade. I am also having trouble getting it to output to a text file. Here is my script:

REM COMP230 INTRODUCTION TO SCRIPTING AND DATABASE WITH LAB



REM Author:Cooper McKay SECTION ID: 230 Date: 9-10-07

REM



REM LAB 7 - Decision making

REM Script name: L7-grades.bat

REM Function:

REM This Script is used to calculate grades of students.



@echo off

cls



REM echo follows by a . generates a blank line

echo.



echo ========

Echo this program calculates student grades of students and outputs them to a text file.

echo ========

echo.



REM Convert first argument to integer

set /a id=%1

set /a grades=%2



if %id% lss 1 goto student id-error else (

if %grades% lss 1 goto grade-error else (

)

)





echo. > l7-grades.txt

echo Student ID Scores Grade

echo ---------- ------ -------

REM Outputs above message to l7-grades.txt

REM del l7-grades.txt





if %grades% GTR 89 (echo %id% A) else (



if %grades% GTR 79 echo %id% B



if %grades% GTR 69 echo %id% C



if %grades% GTR 60 echo %id% D



if %grades% LSS 60 echo %id% F

)



)







goto :EOF



:grade-error

Echo **Error: The grades must be greater than zero

goto :EOF



:studentid-error

Echo **Error: The student id number must be greater than zero.

goto :EOF

)

)
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,180
519
126
Well, simple issue, here... you never do an "echo %grades%" anywhere in your code.... I would also set the letter of the grade to a variable and just do a single echo statement at the end...

So that instead of an "echo %id% A" in each of those if statements, I would do a set gradeval=A, set gradeval=B, set gradeval=C, etc., etc., and at the end of that section, after the if statements are closed, do a "echo %id% %gradeval% %grades%" or whatever format you need them to be in....
 

Fallen Kell

Diamond Member
Oct 9, 1999
6,180
519
126
I am not sure I understand what your question is then. Isn't the input to your program, "<student id> <number grade>" for which you store the input number grade as the variable "%grades%"? That at least is what you are doing the large if/else if/else statement against for it being GTR a numberical value.... So all you need to do is add the %grades% to the echo in each of those lines...

For instance:

if %grades% GTR 89 (echo %id% A) else (

Needs to be changed to:

if %grades% GTR 89 (echo %id% %grades% A) else (


And do that for all the other lines in that section.