FinalGear.com Forums  

Go Back   FinalGear.com Forums > General Discussion > Technology

Welcome to the FinalGear.com Forums!

This is the place to discuss everything related to Top Gear, Fifth Gear, and more! However, to gain full access to these forums, you will need to register. As a registered member, you will be able to:

  • Remove all ads from the forums. If you've taken the time to register, we'll thank you by not bothering you with them.
  • Make your own posts and threads. The shows' producers have been known to read these forums, so you may just influence the shows by posting here!
  • View the Video Offers and Video Requests forums which contain lots of great content.
  • Get to know a bunch of friendly people and participate in an ever-growing community.

All this and much more is available to you absolutely free when you register for an account, so sign up today!

If you have any problems with the registration process or logging into your account, you can contact us. Already have an account? Login to the upper-right to hide this message and all advertisements on the forums.


Technology Computers, gadgets and everything else.

Reply
 
LinkBack Thread Tools Search this Thread
Old November 29th, 2006, 07:09 PM   #1
 
patrick10's Avatar
 
Joined: Dec 1st, 2004
Last Online: Yesterday
Location: ohio, usa
Posts: 1,248
Car: 240, audi 5000, soon to be 240#2
Rep Power: 0
patrick10 has between 0 and 9 reputation
Default Anyone good at basic programing?

i need some help with my homework.

i need to use arrays to store multiple values for inputs and display the results in a table format.

this is what i have so far. i missed this class due to doctors appointment and my professor is a dumbass and cant even do it.

Quote:
1 CLS
100 REM NAME & DATE
110 REM -----------
120 REM
130 REM PATRICK HOLLAND 11/29/06
180 REM
190 REM -----------------------------------------------------------------
200 REM PROGRAM NAME
210 REM ------------
220 REM
230 REM CYL-1IF
280 REM
290 REM -----------------------------------------------------------------
300 REM PROGRAM DESCRIPTION
310 REM -------------------
320 REM
330 REM THIS PROGRAM WILL CALCULATE THE CIRCLE AREA, CIRCUMFERENCE, VOLUME,
340 REM AND SURFACE AREA OF A CYLINDER
380 REM
390 REM -----------------------------------------------------------------
400 REM CONSTANTS
410 REM ---------
420 REM
430 LET PI = 3.14
480 REM
490 REM -----------------------------------------------------------------
500 REM VARIABLES
510 REM ---------
520 REM
530 REM R = RADIUS OF THE CYLINDER
535 REM A = AREA OF THE CIRCLE IN THE CYLINDER
540 REM SA = SURFACE AREA OF THE CYLINDER
550 REM C = CIRCUMFERENCE OF THE CYLINDER
560 REM V = VOLUME OF THE CYLINDER
570 REM H = HEIGHT OF THE CYLINDER
580 REM
590 REM -----------------------------------------------------------------
1000 REM MAIN PROGRAMING BLOCK
1010 REM ---------------------
1020 REM
1030 GOSUB EXPLAIN
1040 INPUT "HOW MANY TIMES WOULD YOU LIKE TO RUN THE PROGRAM"; ANS
1050 IF ANS >= 1 THEN GOTO 1080
1060 PRINT "INCORRECT RESPONCE, TRY AGAIN"
1070 GOTO 1040
1080 LET COUNT = 0
1110 GOSUB INPT
1120 GOSUB CALCS
1130 GOSUB OUTPT
1140 LET COUNT = COUNT + 1
1150 IF COUNT < ANS GOTO 1110
1160 IF COUNT >= ANS GOTO 1970
1970 END
1980 REM
1990 REM ----------------------------------------------------------------
2000 REM EXPLAIN PROGRAM TO USER
2010 REM -----------------------
2020 REM
2030 EXPLAIN:
2040 PRINT "THIS PROGRAM WILL ALLOW THE USER TO ENTER THE NUMBER OF"
2050 PRINT "TIMES THE PROGRAM WILL RUN; OBTAIN THE NECESSARY"
2060 PRINT "DIMENSIONS FROM THE USER; CALCULATE THE VOLUME AND"
2070 PRINT "SURFACE AREA OF THE CYLINDER; AND DISPLAY THE RESULTS"
2080 PRINT "OF THE CALCULATIONS."
2090 PRINT ""
2970 RETURN
2980 REM
2990 REM ----------------------------------------------------------------
3000 REM INPUT
3010 REM -----
3020 REM
3030 INPT:
3035 PRINT ""
3040 INPUT "ENTER THE RADIUS OF THE CYLINDER"; R
3050 INPUT "ENTER THE HEIGHT OF THE CYLINDER"; H
3060 INPUT " ENTER THE UNITS"; U$
3970 RETURN
3980 REM
3990 REM ----------------------------------------------------------------
4000 REM CALCULATIONS
4010 REM ------------
4020 REM
4030 CALCS:
4040 LET A = PI * R ^ 2
4050 LET C = PI * R * 2
4060 LET V = A * H
4070 LET SA = C * H
4970 RETURN
4980 REM
4990 REM ----------------------------------------------------------------
5000 REM OUTPUT
5010 REM ------
5020 REM
5030 OUTPT:
5031 PRINT ""
5032 PRINT "THE AREA OF THE CYLINDER IS---------->"; A; "SQ"; U$
5033 PRINT "THE CIRCUMFERENCE OF THE CYLINDER IS->"; C; ""; U$
5034 PRINT "THE VOLUME OF THE CYLINDER IS-------->"; V; "CU"; U$
5035 PRINT "THE SURFACE AREA OF THE CYLINDER IS-->"; SA; "SQ"; U$
5036 PRINT ""
5040 RETURN
5980 REM
5990 REM ----------------------------------------------------------------
thanks in advance
__________________
patrick10 is offline   Reply With Quote
Want To Remove This Ad? Just Register For A FREE Account!
Old November 29th, 2006, 07:11 PM   #2
Global Moderator
 
Adunaphel's Avatar
 
Joined: Jan 18th, 2006
Last Online: Yesterday
Location: [ˈne:dərlɑnt]
Age: 29
Posts: 3,597
Car: 1990 Mercedes-Benz 190E (W201)
Rep Power: 67
Adunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond reputeAdunaphel has a reputation beyond repute
Send a message via ICQ to Adunaphel Send a message via MSN to Adunaphel Send a message via Skype™ to Adunaphel
Default

UGH, basic

*goes and have a shower, hoping it is still early enough to prevent contamination*
__________________

01001001 00100000 01000001 01001101 00100000 01010100 01001000 01000101 00100000 01010011 01010100 01001001 01000111
Adunaphel is offline   Reply With Quote
Old November 29th, 2006, 07:48 PM   #3
 
Peter3hg's Avatar
 
Joined: May 3rd, 2006
Last Online: Yesterday
Location: Breast Hill Castle, Angleland
Age: 19
Posts: 3,832
Car: 2006 Yamaha Fazer
LFS Status: LFS Status
Rep Power: 31
Peter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputationPeter3hg has between 1500 and 1999 reputation
Send a message via MSN to Peter3hg
Default

OMFG I love Basic. I had it on a Vtech laptop when I was only a little nipper. Unfortunately that was about 10 years ago so I can't help you.
__________________
Peter3hg is offline   Reply With Quote
Old November 29th, 2006, 08:24 PM   #4
 
jeffy777's Avatar
 
Joined: Feb 8th, 2005
Last Online: Yesterday
Location: US
Age: 27
Posts: 5,662
Car: '04 Toyota Sienna, crippled people like vans....
Rep Power: 53
jeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond reputejeffy777 has a reputation beyond repute
Default

I never messed with BASIC. I stick with web languages like php/mySQL/javascript
__________________

A man named Jeffy once said, "If laziness is craziness, then I've lost my marbles...and I don't feel like trying to find them."
jeffy777 is offline   Reply With Quote
Old November 29th, 2006, 09:12 PM   #5
.sa = bad driver!
 
chaos386's Avatar
 
Joined: Nov 8th, 2004
Last Online: Yesterday
Location: Al-Khobar, Saudi Arabia
Age: 22
Posts: 3,564
LFS Status: LFS Status
Rep Power: 62
chaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond repute
Default

Basic is great if it's on a platform with a lot of built-in functions, like a graphing calculator, because you can make useful, small, and simple programs very quickly.

For anything else, run away. Run very far away. Learning Basic to make complicated programs will just teach you bad habits and make you used to writing spaghetti code. I suggest learning C or C++ first. They're low-level enough that the hardware is fairly exposed to you, and you're forced to do some memory management, which is a good learning experience. They're high-level enough though, that you focus on making functions rather than spaghetti code, and C++ will teach you how to make good object-oriented code (and if you want to learn programming, you MUST learn how to make good OO code!).

Then later on you can learn a language like Python or Java, or one of the scripting languages.

Here's what your code would look like in C++:

(EDIT: Fixed the error Adunaphel noticed, but with const instead of #DEFINE images/smilies/tongue.gif)

Code:
#include <iostream.h>
#include <stdlib.h>

/* Name		- 
   Date		-
   Program Name	-

Program Description:
   This Program will calculate the circle area, circumference, volume, and surface area of a cylinder
*/

//Constants
const double PI = 3.141592654;

//Function declarations
double circle_circumference(double radius);
double circle_area(double radius);
double cylinder_area(double radius, double height);
double cylinder_volume(double radius, double height);

//Main loop
int main()
{
	double 	r, h, circumference, area, surface_area, volume;
	int 	run_times, i;

	// BEGIN WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
	system("CLS");
	// END WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK

	// Explain the program to the user	
	cout << "THIS PROGRAM WILL ALLOW THE USER TO ENTER THE NUMBER OF" << endl;
	cout << "TIMES THE PROGRAM WILL RUN; OBTAIN THE NECESSARY" << endl;
	cout << "DIMENSIONS FROM THE USER; CALCULATE THE VOLUME AND" << endl;
	cout << "SURFACE AREA OF THE CYLINDER; AND DISPLAY THE RESULTS" << endl;
	cout << "OF THE CALCULATIONS." << endl << endl;

	do
	{	
		cout << "How many times would you like to run the program? ";
		cin >> run_times;

		if (runtimes < 1)
		{
			cout << "Incorrect response, try again" << endl;
		}
	}
	while (run_times < 1);

	for (i = 1 ; i <= run_times ; i++)
	{
		// Get the input from the user
		cout << "\n Enter the radius of the cylinder: ";
		cin >> r;
		cout << "Enter the height of the cylinder: ";
		cin >> h;		

		// Calculate the info
		circumference = circle_circumference(r);
		area = circle_area(r);
		surface_area = cylinder_area(r,h);
		volume = cylinder_volume(r,h);

		// Print the answers
		cout << "The area of the base of the cylinder is " << area << ".\n";
		cout << "The circumference of the base of the cylinder is " << circumference << ".\n";
		cout << "The surface area of the cylinder is " << surface_area << ".\n";
		cout << "The volume of the cylinder is " << volume << ".\n\n";
	}

	return 0;
}

//Functions
double circle_circumference(double radius) {return 2*PI*radius;}
double circle_area(double radius){return PI*radius*radius;}
double cylinder_area(double radius, double height){return (2*PI*radius*radius + 2*PI*radius*height);}
double cylinder_volume(double radius, double height){return PI*radius*radius*height;}
You could write the program without the "Calculate the info" section if you wanted to (by placing the functions directly into the output section), but I've put it in to make the program easier to read and debug. If I were writing a program like this, I'd do it a little differently, however:

Code:
#include <iostream.h>
#include <stdlib.h>

/* Name		- 
   Date		-
   Program Name	-

Program Description:
   This Program will calculate the circle area, circumference, volume, and surface area of a cylinder
*/

//Constants
const double PI = 3.141592654;

//Function declarations
double circle_circumference(double radius);
double circle_area(double radius);
double cylinder_area(double radius, double height);
double cylinder_volume(double radius, double height);

//Main loop
int main()
{
	double 	r, h, circumference, area, surface_area, volume;
	char repeat;

	// BEGIN WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK
	system("CLS");
	// END WINDOWS COMMAND LINE-SPECIFIC CODE BLOCK

	// Explain the program to the user	
	cout << "This program calculates the volume and surface area of a cylinder, as well as the area and circumference of its base. You can run as many different calculations as you like.\n\n";

	do
	{
		// Get the input from the user
		cout << "\n Enter the radius of the cylinder: ";
		cin >> r;
		cout << "Enter the height of the cylinder: ";
		cin >> h;		

		// Calculate the info
		circumference = circle_circumference(r);
		area = circle_area(r);
		surface_area = cylinder_area(r,h);
		volume = cylinder_volume(r,h);

		// Print the answers
		cout << "The area of the base of the cylinder is " << area << ".\n";
		cout << "The circumference of the base of the cylinder is " << circumference << ".\n";
		cout << "The surface area of the cylinder is " << surface_area << ".\n";
		cout << "The volume of the cylinder is " << volume << ".\n\n";

		// Ask if they'd like to do it again
		cout << "Would you like to do another calculation? (y/n) ";
		cin >> repeat;  // We just want the first letter
		cin.ignore(80,'\n');	// Discard the rest, i.e. "es" or "o"
	}
	while (repeat == 'y' || repeat == 'Y');

	return 0;
}

//Functions
double circle_circumference(double radius) {return 2*PI*radius;}
double circle_area(double radius){return PI*radius*radius;}
double cylinder_area(double radius, double height){return (2*PI*radius*radius + 2*PI*radius*height);}
double cylinder_volume(double radius, double height){return PI*radius*radius*height;}
As a disclaimer, I haven't tried to compile any of the above code blocks, so there could be errors.
__________________
"Shit, that's a busy table cloth." -matt2000

Last edited by chaos386; November 30th, 2006 at 10:09 AM..
chaos386 is offline   Reply With Quote
Old November 29th, 2006, 09:48 PM   #6
Lazy Head Dude
 
Viper007Bond's Avatar
 
Joined: Sep 21st, 2003
Last Online: Yesterday
Location: Portland, Oregon
Posts: 21,086
Car: Dodge Viper (I wish!)
Rep Power: 237
Viper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond repute
Default

Quote:
Originally Posted by jeffy777 View Post
I never messed with BASIC. I stick with web languages like php/mySQL/javascript
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>patrick10's Cylinder Calculator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style type="text/css">body { font-family: Courier New; }</style>
</head>
<body>

<?php

// If form submit, handle the results
if ( $_POST['radius'] && $_POST['height'] && $_POST['units'] ) {

    
// Sanitize the input
    
$radius = (int) $_POST['radius'];
    
$height = (int) $_POST['height'];
    
$units ' ' htmlspecialchars($_POST['units']);

    
// Calculate the results
    
$area pi() * $radius 2;
    
$circ pi() * $radius 2;
    
$volume $area $height;
    
$sa $circ $height;
    
    
?>
<pre>
The area of the cylinder is:           <?php echo round($area2) . $units?>^2
The circumference of the cylinder is:  <?php echo round($circ2) . $units?>

The volume of the cylinder is:         <?php echo round($volume2) . $units?>^3
The surface area of the cylinder is:   <?php echo round($sa2) . $units?>^2

<a href="<?php echo $_SERVER['PHP_SELF']; ?>">&laquo; Back</a>
</pre>
<?php
} else {
?>
<form method="post" action="">

<p style="padding-bottom: 25px">This program will obtain the necessary dimensions from the user, calculate the volume and surface<br />
area of the cylinder, and display the results of the calculations.</p>

<?php if ( $_POST ) echo '<p><strong>Please fill in all fields!</strong></p>'?>

<p>Cylinder radius: <input type="text" name="radius" size="20" value="<?php echo htmlspecialchars($_POST['radius']); ?>" /></p>
<p>Cylinder height: <input type="text" name="height" size="20" value="<?php echo htmlspecialchars($_POST['height']); ?>" /></p>
<p>Units abbreviation or name: <input type="text" name="units" size="10" value="<?php echo htmlspecialchars($_POST['units']); ?>" /></p>

<p><input type="submit" name="submit" value="Calculate &raquo;" /></p>

</form>
<?php
}
?>

</body>
</html>
http://test.viper007bond.com/patrick10_cylinder.php

images/smilies/whistling.gif
__________________
Fight back against the evil Quiky by +1'ing this post!

There is no replacement for displacement.
- Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10

... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it.
- Motor Trend on the 2006 Dodge Viper Coupe, November 2005
Viper007Bond is offline   Reply With Quote
Old November 29th, 2006, 09:57 PM   #7
 
geeman's Avatar
 
Joined: Apr 18th, 2005
Last Online: 02:16 AM
Location: Finland
Age: 22
Posts: 826
LFS Status: LFS Status
Rep Power: 24
geeman has between 650 and 999 reputationgeeman has between 650 and 999 reputationgeeman has between 650 and 999 reputationgeeman has between 650 and 999 reputationgeeman has between 650 and 999 reputationgeeman has between 650 and 999 reputationgeeman has between 650 and 999 reputation
Send a message via MSN to geeman
Default

My version is in Java images/smilies/smile.gif
I need to learn basics of Java for a data types & algorithms exam. It only runs once and there might be some bugs.

Code:
/*
 * Cylinder.java
 *
 * Created on 29. marraskuuta 2006, 23:02
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Tuomas
 */
public class Cylinder {
    public static double R, A, SA, C, V, H;
    
    /* Calculation functions
     */
    
    public static void calcArea() {
        A = Math.PI *R*R;
    }
    
    public static void calcCircumference() {
       C = Math.PI *R*2; 
    }
    
    public static void calcVolume() {
        V = A*H;
    }
    
    public static void calcSurface() {
        SA = C*H;
    }
    
    /* Main starts here
     */
    public static void main(String args[])
    {
        System.out.println("THIS PROGRAM WILL ALLOW THE USER TO ENTER THE NUMBER OF\nTIMES THE PROGRAM WILL RUN; OBTAIN THE NECESSARY\nDIMENSIONS FROM THE USER; CALCULATE THE VOLUME AND\nSURFACE AREA OF THE CYLINDER; AND DISPLAY THE RESULTS\nOF THE CALCULATIONS.");
        
        /* Input the variables
         */
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the radius of the cylinder: ");
        R = input.nextDouble();
        System.out.println("Enter the height of the cylinder: ");
        H = input.nextDouble();
        
         input.close();
         /* Using the calc-functions to calculate
         */
        
        calcArea();
        calcCircumference();
        calcVolume();
        calcSurface();
        
        System.out.println("Area: " + A + "\nCircumference: " + C + "\nVolume: " + V + "\nSurface Area: " + SA);
    }
    
}
__________________
This space has been reserved.
geeman is offline   Reply With Quote
Old November 29th, 2006, 09:59 PM   #8
Lazy Head Dude
 
Viper007Bond's Avatar
 
Joined: Sep 21st, 2003
Last Online: Yesterday
Location: Portland, Oregon
Posts: 21,086
Car: Dodge Viper (I wish!)
Rep Power: 237
Viper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond repute
Default

images/smilies/lmao.gif That makes 3 solutions now in languages other than the one he wanted. Too funny.
__________________
Fight back against the evil Quiky by +1'ing this post!

There is no replacement for displacement.
- Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10

... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it.
- Motor Trend on the 2006 Dodge Viper Coupe, November 2005
Viper007Bond is offline   Reply With Quote
Old November 29th, 2006, 10:02 PM   #9
.sa = bad driver!
 
chaos386's Avatar
 
Joined: Nov 8th, 2004
Last Online: Yesterday
Location: Al-Khobar, Saudi Arabia
Age: 22
Posts: 3,564
LFS Status: LFS Status
Rep Power: 62
chaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond reputechaos386 has a reputation beyond repute
Default

^Your area calculation doesn't seem to be multiplying by pi.

I like how we've translated his program into three other languages, but have completely forgotten his original question, which is how to use arrays and tables in Basic. images/smilies/tongue.gif
__________________
"Shit, that's a busy table cloth." -matt2000
chaos386 is offline   Reply With Quote
Old November 29th, 2006, 11:44 PM   #10
 
andyhui01's Avatar
 
Joined: Jun 4th, 2004
Last Online: 12:33 AM
Location: Melbourne, Australia
Age: 20
Posts: 8,514
Car: 00' Subaru Forester GT
LFS Status: LFS Status
Rep Power: 28
andyhui01 has between 50 and 149 reputationandyhui01 has between 50 and 149 reputation
Send a message via MSN to andyhui01 Send a message via Yahoo to andyhui01 Send a message via Skype™ to andyhui01
Default

how you guys can write those programs amazes me, I struggled with Basic MATLAB images/smilies/lol.gif, and I'm going to have to do Java next semester, I'll prob. be posting in this thread quite alot images/smilies/lol.gif
__________________
andyhui01 is offline   Reply With Quote
Old November 29th, 2006, 11:48 PM   #11
Lazy Head Dude
 
Viper007Bond's Avatar
 
Joined: Sep 21st, 2003
Last Online: Yesterday
Location: Portland, Oregon
Posts: 21,086
Car: Dodge Viper (I wish!)
Rep Power: 237
Viper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond reputeViper007Bond has a reputation beyond repute
Default

I totally fucked up the radius to the 2nd power part (never done a power in PHP before) and I stupidly used "(int)" to make the input a number forgetting that that would make it an integer. Here it is all fixed. images/smilies/dry.gif

Oh, and chaos386 also pointed out to me that you forgot to add the area of the ends to get the total surface area (I just copied your math). Fixed it in my script though.

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>patrick10's Cylinder Calculator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style type="text/css">body { font-family: Courier New; }</style>
</head>
<body>

<?php

// If form submit, handle the results
if ( is_numeric($_POST['radius']) && is_numeric($_POST['height']) && $_POST['units'] ) {

    
// Calculate the results
    
$area pi() * pow($_POST['radius'], 2);
    
$circ pi() * $_POST['radius'] * 2;
    
$volume $area $_POST['height'];
    
$sa = ($circ $_POST['height']) + ($area);

    
$units ' ' htmlspecialchars($_POST['units']);

    
?>
<pre>
The area of the cylinder is:           <?php echo round($area2) . $units?>^2
The circumference of the cylinder is:  <?php echo round($circ2) . $units?>

The volume of the cylinder is:         <?php echo round($volume2) . $units?>^3
The surface area of the cylinder is:   <?php echo round($sa2) . $units?>^2

<a href="<?php echo $_SERVER['PHP_SELF']; ?>">&laquo; Back</a>
</pre>
<?php
} else {
?>
<form method="post" action="">

<p style="padding-bottom: 25px">This program will obtain the necessary dimensions from the user, calculate the volume and surface<br />
area of the cylinder, and display the results of the calculations.</p>

<?php if ( $_POST ) echo '<p><strong>Please fill in all fields!</strong></p>'?>

<p>Cylinder radius: <input type="text" name="radius" size="20" value="<?php echo htmlspecialchars($_POST['radius']); ?>" /></p>
<p>Cylinder height: <input type="text" name="height" size="20" value="<?php echo htmlspecialchars($_POST['height']); ?>" /></p>
<p>Units abbreviation or name: <input type="text" name="units" size="10" value="<?php echo htmlspecialchars($_POST['units']); ?>" /></p>

<p><input type="submit" name="submit" value="Calculate &raquo;" /></p>

</form>
<?php
}
?>

</body>
</html>
__________________
Fight back against the evil Quiky by +1'ing this post!

There is no replacement for displacement.
- Wolfgang Bernhard, Chief Operating Officer, Chrysler Group talking about the Dodge Viper SRT-10

... I ask Herb Helbig, vehicle synthesis manager for SRT and a member of the original Team Viper development group since day one, if they'd ever thought of adding traction control. "It comes with two," he says, pointing at my feet. "Learn to use them." Got it.
- Motor Trend on the 2006 Dodge Viper Coupe, November 2005
Viper007Bond is offline   Reply With Quote
Old November 30th, 2006, 12:03 AM   #12
 
Greatgraddage's Avatar
 
Joined: Jun 7th, 2004
Last Online: 12:11 AM
Location: Wales, UK
Age: 22
Posts: 1,007
Car: 205 1.9 GTI
Rep Power: 23
Greatgraddage has between 350 and 449 reputationGreatgraddage has between 350 and 449 reputationGreatgraddage has between 350 and 449 reputationGreatgraddage has between 350 and 449 reputation
Send a message via ICQ to Greatgraddage Send a message via MSN to Greatgraddage
Default

BASIC ruled. I wrote an ASCII snake game in qbasic for dos ages ago. Started writing an rpg too, got the graphics working but couldn't quite get it running smoothly and lost interest.

When is this in for? Writing a report at the moment so won't have time till friday at earliest. Hopefully you'll decipher one of the above ok!
__________________
Currently Drive - 205 GTI
Currently Want - 1967 Mustang GT500 (Eleanor!)
Greatgraddage is offline   Reply With Quote
Old November 30th, 2006, 12:24 AM   #13
vRS
 
vRS's Avatar
 
Joined: Nov 22nd, 2004
Last Online: Yesterday
Location: Stirling, Scotland
Age: 17
Posts: 1,567
Rep Power: 25
vRS has between 650 and 999 reputationvRS has between 650 and 999 reputationvRS has between 650 and 999 reputationvRS has between 650 and 999 reputationvRS has between 650 and 999 reputationvRS has between 650 and 999 reputationvRS has between 650 and 999 reputation
Send a message via MSN to vRS
Default

I use Visual Basic at school, I'm OK at it but wish we used the newer one, the old one is so Windows 98. Are there any sits that can teach you to get better at it?
vRS is offline   Reply With Quote
Old November 30th, 2006, 12:36 AM   #14
Hormone Induced
 
BerserkerCatSplat's Avatar
 
Joined: Jun 21st, 2005
Last Online: 02:32 AM
Location: Calgary, Alberta, Canada
Posts: 5,911
Car: Pimpmobile
Rep Power: 73
BerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond reputeBerserkerCatSplat has a reputation beyond repute
Default

Ugh, haven't done Basic in 10 years. I cant' remember it, I stick to C++.
__________________

OSPhoto
BerserkerCatSplat is offline   Reply With Quote
Old November 30th, 2006, 12:55 AM   #15
 
Greatgraddage's Avatar
 
Joined: Jun 7th, 2004
Last Online: 12:11 AM
Location: Wales, UK
Age: 22</