Anyone good at basic programing?

patrick10

Well-Known Member
Joined
Dec 1, 2004
Messages
1,343
Location
ohio, usa
Car(s)
s13 and a beater daily
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.

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
 
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.
 
I never messed with BASIC. I stick with web languages like php/mySQL/javascript
 
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 :p)

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.
 
Last edited:
I never messed with BASIC. I stick with web languages like php/mySQL/javascript

PHP:
<!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($area, 2) . $units; ?>^2
The circumference of the cylinder is:  <?php echo round($circ, 2) . $units; ?>

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

<a href="<?php echo $_SERVER['PHP_SELF']; ?>">« 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 »" /></p>

</form>
<?php
}
?>

</body>
</html>

http://test.viper007bond.com/patrick10_cylinder.php

:whistle:
 
My version is in Java :)
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);
    }
    
}
 
:lmao: That makes 3 solutions now in languages other than the one he wanted. Too funny.
 
^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. :p
 
how you guys can write those programs amazes me, I struggled with Basic MATLAB :lol:, and I'm going to have to do Java next semester, I'll prob. be posting in this thread quite alot :lol:
 
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. <_<

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:
<!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']) + (2 * $area);

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

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

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

<a href="<?php echo $_SERVER['PHP_SELF']; ?>">« 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 »" /></p>

</form>
<?php
}
?>

</body>
</html>
 
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!
 
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?
 
http://www.qbasic.com has some VERY good forums , but be careful about making it look too much like homework! They'll point you in the right direction. Also goto is bad, remember that!
 
If you don't mind my asking,

why BASIC? the only thing it's good for is
10 Print "boobies"
20 goto 10
 
If you don't mind my asking,

why BASIC? the only thing it's good for is
10 Print "boobies"
20 goto 10

:lmao: And now you've proved that GOTO can actually be of good use.
 
Isnt it stupid to still teach students procedural programming insted of Object Oriented?
 
Isnt it stupid to still teach students procedural programming insted of Object Oriented?

I don't agree with you on that one. For someone who is just starting it's probably the best way to go. I can assure you that as someone who actually teaches programming using both paradigms.
 
Top