Jump to content

This is what I got and what is being needed.


Dtp1337

Recommended Posts

This is what I have interpreted. I am having a really hard time with this since I had to take my kid to the doctor and missed a day of class. Could one look over my code and please... PLEASE... ! Help me figure out what I'm doing wrong and correct me so that I can actually SEE my mistakes since I'm totally a fish out of water. Loop and Decision Structure with Form Input 2Purpose:In this lab you will write a php program and input form. The input form will pass information to the php program which will process the data.Procedure:Write an HTML form that will ask the user for a starting and ending integer and an increment. Those values will be passed to a php program. You may use either a GET or POST method to send the data.Write a php program that will accept the data from the form.The program should check that the start value is smaller than the stop value and the increment is positive or that the stop value is smaller than the start value and the increment is negative. If the both of those conditions are false, send an error to the web browser.If a valid condition exists, print the values starting at the start value, ending at the end value in increments of the increment entered.Example:Start 10End 20Increment -1Output error messageStart 20End 0increment -5Output20151050

CISP1720-dpatter3-Lab05-1.php

CISP1720-dpatter3-Lab05-F.php

Link to comment
Share on other sites

This will get you started. Generally, a members personal situation isn't considered relevant. So, next time you need help please just post your question without the personal background. Also, please note that I edited out the var_dump, changed your while statement to an if statement (YOU MY NEED TO CHANGE IT BACK) and set each argument in the if statement apart with parens and dropped the semi colon in that statement. If I left the while statement, the script would time-out. Please let us know if you need more help and remember you're using-up a lot of at-a-boys (or girls) because newbies sometimes get a pass on Sundays nights. Finally, don't forget to follow your own topic (see upper left).

<!DOCTYPE HTML> <?php /********************************************** Author: Dylan T. Patterson* Filname: CISP1720-dpatter3-LAB05.php* Assignment: CISP1720-dpatter3-LAB05.php* Date: 9/19/2012* Description: Displays Annual and Monthly interest of a loan.*********************************************/  ?> <html><head><meta a http-equiv="Content-Type" content="text/html; charset=utf-8"><title> CISP1720 Lab 4</title></head> <h1> Lab 4 </h1><h3> Starting and Ending integers provided.</h3><body><p>  <?php  $Start=$_GET['Start'];  $End=$_GET['End']; //echo var_dump($_GET);   if (($Start < $End) or ($Start < 0)){  echo "<p><b> ERROR# Your starting integer is less than or equal to the ending integer or the number used is a negative. <b></p>" ;}  echo "<p> Start = $Start </p> \n" ;  echo "<p> End = $End </p> \n" ;  For ($i=$Start; $i>$End; $i = $i - 1) {  echo "<p> Incremented = $i </p> \n" ;  }    ?>   </body></html>

Edited by niche
Link to comment
Share on other sites

Also, regarding your need to "see" your mistake, That's exactly what was happening when you got a parse error in line 38. You were in fact seeing your error. You need to learn what to do about it. A parse error is the most frequent error in php and the easiest error to fix. It usually means you forgot a semicolon, but in this case your placed a semi colon in your while statement where it didn't belong.

Edited by niche
Link to comment
Share on other sites

Thank you alot for helping. But I still have the problem where I need the increment as you've provided, and as well as with the error message for the starting number being less than the ending integer. I do not understand at-a-boys or girls. But this is how I see what is needed. If Start < End (something about a negative increment?) Start =End =Increment = -1 < how do I get the error apge to show the -1 on increments... due to the start being smaller then the end.Error Message Else If Start > End (something about postive increment)Start =End =Increment = -5 2015105 Do exactly what you provided me, but in increments of 5. which I know is just changing 1 to 5 i think. Others have said something about the algebra changing the increments because of the negatives. Again I am a newb. I'm taking this course to learn, but out of 5 assignments this is the first to stump me. I also appreciate you stopped to take time to help me on a Sunday night. It's not due until Tuesday but I do have a array program to learn and write by thursday if anyone would be open to it when I get this one sorted out. I honestly need a friend to one on one with so I have a spotter to smack my hand with a ruler when I do something wrong then explain to me why. I added what I changed to the file for what I've progressed from your help. The If statement is needed from what I'm aware of, as well as, an Else and another If. Sorry for drama. I just didn't expect a response so fast. If I had known you were on I'd loved to pick your brain to ehance my own. Also apologies for not be very specific. <!DOCTYPE HTML> <?php /********************************************** Author: Dylan T. Patterson* Filname: CISP1720-dpatter3-LAB05.php* Assignment: CISP1720-dpatter3-LAB05.php* Date: 9/19/2012* Description: Displays Annual and Monthly interest of a loan.*********************************************/ ?> <html><head><meta a http-equiv="Content-Type" content="text/html; charset=utf-8"><title> CISP1720 Lab 4</title></head> <h1> Lab 4 </h1><h3> Starting and Ending integers provided.</h3><body><p> <?php $Start=$_GET["Start"]; $End=$_GET["End"]; If (($Start<$End or $Start < 0)){ echo "<p><b> ERROR# Your starting integer is less than or equal to the ending integer or the number used is a negative. <b></p>" ; echo "<p> Start = $Start </p> \n" ; echo "<p> End = $End </p> \n" ; For ($i=$Start; $i>$End; $i = -$i - -1) { echo "<p> Incremented = $i </p> \n" ; } If Else(($Start>$End or $Start > 0)){ echo "<p> Start = $Start </p> \n" ; echo "<p> End = $End </p> \n" ; For ($i=$Start; $i>$End; $i = $i + -5) { echo "<p> Incremented = $i </p> \n" ; } } } ?> </body></html>

Edited by Dtp1337
Link to comment
Share on other sites

The at-a-boys (girls) is simply a reminder that you shouldn't expect to get answers right a way simply because you need them. Anyway, you need an if-else statement -

if (($Start < $End) or ($Start < 0)){  //echo error} else {  //echo results of for loop}

Edited by niche
Link to comment
Share on other sites

Actually, you shouldn't need to restrict any loop. A loop can count upwards or downwards. You just need to make sure that the increment value has the right sign.

Link to comment
Share on other sites

I spoke to my proffessor today and this is what he gave me. If (Start > End) If(inc<0)Loop what i got ElseError Else [start< 0]If inc>0Loop ElseError He also said I could use an and. (Start>End) and inc < 0 Could you help me beter understand these steps. Please.

Link to comment
Share on other sites

Here's the description of the problem:

The program should check that the start value is smaller than the stop value and the increment is positive or that the stop value is smaller than the start value and the increment is negative. If the both of those conditions are false, send an error to the web browser.
You can write your code so that it reads like that description. So, start with this:
The program should check that the start value is smaller than the stop value and the increment is positive
The start value is smaller than the stop value and the increment is positive. if ($start < $stop && $increment > 0) Then go to this part:
or that the stop value is smaller than the start value and the increment is negative
That looks like this: if ($stop < $start && $increment < 0) The description has an "or" in it, so you can combine those two cases with an or operator by wrapping each case in parentheses:
if (($start < $stop && $increment > 0) || ($stop < $start && $increment < 0)){  // run the loop}else{  // show an error}

The loop needs to change slightly based on whether the increment is positive or negative. If the increment is positive: for ($i = $start; $i <= $stop; $i += $increment) and if it's negative: for ($i = $start; $i >= $stop; $i += $increment) The only thing that changes is the condition in the middle. So inside the if statement you can do another if statement where you check if the increment is positive or negative, and run the appropriate loop.

Link to comment
Share on other sites

If the start is less than the end, the increment needs to be positive. You can use a while() or for() loop. Generally the for() loop is more convenient. [Read about for loops]The increment is the amount that you add to the iterator ( $i ) on each iteration. (The word "iteration" refers to each time the loop is repeated)

Link to comment
Share on other sites

Dtp1337, that's the kind of service you get here. ingolme & justsomeguy are two of the heaviest hitters we have.

Edited by niche
Link to comment
Share on other sites

You guys are really awesome. You know what your doing. Thank you so much for the information. I've burnt through 3 - 4 angles at trying to get the right order for this thing. My brain hurts. I honestly feel like this since starting my programming/network degrees. http://memegenerator.net/instance/23473055 If it's cool for me to continue to post and hang around throughout the semester(and longer) I'd really enjoy getting a better perspective of things.

Link to comment
Share on other sites

Well I thought I had it... Where am I going wrong.... ughhhh... it is totally different from what he gave me. I don't understand Nesting If and Else efficiently. <?php $Start=$_GET["Start"]; $End=$_GET["End"]; $Increment=$_GET["End"]; if ($Start <=$End && $Increment > 0){ For ($Num1 = $Start; $Num1 <= $End; $Num1 += $Increment) Else { echo "<p><b> ERROR# Your starting integer is less than or equal to the ending integer or the number used is a negative. <b></p>" ; } } if ($Start >= $End && $Increment < 0){ For(Num2 = $Start; $Num2 >= $End; Num2 += $Increment) Else { echo "<p><b> ERROR# Your starting integer is less than or equal to the ending integer or the number used is a negative. <b></p>" ; } } ?>

Link to comment
Share on other sites

You're not closing your if() block before starting the else block. "else" should be written in lowercase.Be sure to indent your code to see the structure.

if(condition) {  // Code} else {  // Alternative code}

You should have something inside your for() loops as well.

for( ... ) {    // Code to be repeated}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...