Jump to content

Having trouble with a HS GPA(4.0 scale) Calculator


L_Dante

Recommended Posts

I understand the basics of PHP enough to make forms and such and even a little to do calculations, but I've run into a little bit of a snag. What seemed like it would be extremely simple has advanced to a little more than I could chew. I can't figure out how to set a letter(grades, i.e. a b c d f) equal to its corresponding value(a=4, b=3, c=2, d=1, f=0). Simple for most of you... I can't seem to put it in the right order nor figure out a way to successfully calculate it with all the properties for the GPA.

 

If you aren't aware the way to calculate a GPA is you have a set number of classes(1-6) and each class you get a grade, ABCDF, add the variables together then divide by the number of classes.

 

It is set like this: a=4 b=3 c=2 d=1 f=0 x=classes(1-6)

GPA= grade from each class added together/x

 

Trouble is I have to make a html dropdown list stating 1-6 then having it list several forms underneath(# of forms depends on dropdown list) and having each grade be entered as the letter itself and have a calculate button that will add the values then divide by the number of classes... I don't know how to retain the # of classes on the same page.

 

I have no idea how to make it organized but if you have ideas, please let me know. :)

 

I have been trying for hours on this, I really need tips and examples and solutions. I'm a n00b at this web design in general and I know this is a large endeavor but I hope to learn a lot from it.

 

Thank you very much for helping/considering to help.

Link to comment
Share on other sites

I remade a layout for it with html... I'd like to incorporate PHP into still

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
				<p class="subhead">High School 4.0 GPA Calculator<div id="content">

					<p>
	<form id="gpa_calculator" action="gpa.php" method="post" name="gpa_calculator" target="_self"> 
<!-- the above string was on the website  -->
		<fieldset>
			<table border="0" cellspacing="2" cellpadding="0">
				<tr align="right">
					<td width="133">Number of Courses:</td>
					<td><input type="text" name="number_of_courses" value="6" size="4" /></td>
				</tr>
			</table>
			<p><input type="submit" name="submit" value="Submit" /></p>

		</fieldset>
		<p></p>
		<fieldset>
			<table border="0" cellspacing="2" cellpadding="0">
				<tr>
					<td align="center" width="90"></td>

					<td align="center" width="90">Grade</td>

				</tr>
			<tr>
				<td align="center" width="90">Course 1 : </td>
	                        <td align="center" width="90">							<select name="grademenu2">

						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>
					</select>
				</td>

			</tr>
			<tr>
				<td align="center" width="90">Course 2 : </td>
				<td align="center" width="90">							<select name="grademenu2">
						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>
					</select>
				</td>
			</tr>

			<tr>
				<td align="center" width="90">Course 3 : </td>
				<td align="center" width="90">							<select name="grademenu3">
						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>
					</select>
				</td>
			</tr>
			<tr>

				<td align="center" width="90">Course 4 : </td>
				<td align="center" width="90">							<select name="grademenu4">
						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>
					</select>
				</td>
			</tr>
			<tr>
				<td align="center" width="90">Course 5 : </td>
				<td align="center" width="90">							<select name="grademenu5">
						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>

					</select>
				</td>
			</tr>
			<tr>
				<td align="center" width="90">Course 6 : </td>

				<td align="center" width="90">							<select name="grademenu6">
						<option value="1" selected>A</option>
						<option value="2">B</option>
						<option value="3">C</option>
						<option value="4">D</option>
						<option value="5">F</option>
					</select>

				</td>
			</tr>
			</table>
			<p><input type="submit" name="submit" value="Submit" /></p>
			<table border="0" cellspacing="2" cellpadding="0">
				<tr align="right">
				</tr>
				<tr align="right">

					<td>Current GPA:</td>
					<td align="left"><b>0.000</b></td>
				</tr>

			</table>
		</fieldset>
		<p></p>

Link to comment
Share on other sites

  • 2 weeks later...

Are you trying to do this with PHP?  It looks like all html.  If your trying to make a determination on how to output a Grade letter depending on a number, I would use a few traps like:

 

if($gradeNumber < 60)$gradeLetter = "F";
if($gradeNumber >= 60)$gradeLetter = "D";
if($gradeNumber => 70)$gradeLetter = "C";
if($gradeNumber => 80)$gradeLetter = "B";
if($gradeNumber => 90)$gradeLetter = "A";

Since PHP executes Top-Down, it may satisfy more than one of the above statements but it end up with the correct Letter Grade.  If system optimization is an issue you may want to use a more sophisticated statement.

 

If your doing multiple classes, just set a few variables and average the overall by the number of classes.

 

$classesNumber = 6;
$class1 = 70;
$class2 = 90;
$class3 = 80;
$class4 = 60;
$class5 = 90;
$class6 = 80;

$gradeNumber = ($class1 + $class2 + $class3 + $class4 + $class5 + $class6) / $classesNumber;

f($gradeNumber < 60)$gradeLetter = "F";
if($gradeNumber >= 60)$gradeLetter = "D";
if($gradeNumber => 70)$gradeLetter = "C";
if($gradeNumber => 80)$gradeLetter = "B";
if($gradeNumber => 90)$gradeLetter = "A";

//Display Final Grade Letter
echo"$gradeLetter";

 

I don't know if this answered your question.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.