PDA

Click to See Complete Forum and Search --> : My simple cheat my homework prog. :) but it dont work.


factor777
Feb 13th, 2001, 07:19 PM
OK today i desided no more hard math work and i made a program to increase my efficiancy.
calling a function that does stuff aint that easy like vb. please tell me what im forgetting.




#include <stdio.h>
#include <iostream.h>

const double Pi = 3.141592654;
char choice;

int main()
{
printf("a. Cylinder\n");
printf("b. Cone\n");
printf("c. Prism\n");
printf("d. Pyramid\n");
printf("--------------\n");
printf("x. Exit\n");

cin>>choice;

switch ( choice ){
case 'a':
LaSaCylinder();
break;
case 'x':
return 0;
};

};
//////////////////////////
//Cylinder Calculation ///
//////////////////////////
//LA = Lateral Area ///
//////////////////////////
//SA = Surface Area ///
//////////////////////////
void LaSaCylinder(int radius, int hieght, double LA, double SA);
{
cout << "What is the radius of the base?\n";
cin >> radius;
cout << "What is the height of the Cylinder?\n";
cin >> height;

LA = (2 * Pi * radius) * height;
SA = LA + (2 * (Pi * (radius^2)));

cout << LA << " is the Lateral area.\n";
cout << SA << " is the Surface area.\n";
};


this has been more work than i thought! m8's! Heres my craptacular error!
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||
--------------------Configuration: Math - Win32 Debug--------------------
Compiling...
Math.cpp
D:\Ftp\BIN\Math\Math.cpp(21) : error C2065: 'LaSaCylinder' : undeclared identifier
D:\Ftp\BIN\Math\Math.cpp(35) : error C2373: 'LaSaCylinder' : redefinition; different type modifiers
D:\Ftp\BIN\Math\Math.cpp(36) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

Math.exe - 3 error(s), 0 warning(s)
---------------------------------------------------------------------------------------

it just Got worse!

HarryW
Feb 13th, 2001, 07:29 PM
You don't include the return type when you're calling a function, otherwise it's a function declaration. I see people do this a lot, it must be confusing ;)


switch ( choice ){
case 'a':
LaSaCylinder();
break;
case 'x':
return 0;
};


Something like that will do it.

HarryW
Feb 13th, 2001, 07:30 PM
Incidentally, in case you hadn't noticed, that's just the same as in VB :rolleyes:

factor777
Feb 13th, 2001, 07:38 PM
ok its still guaking at me, i dont know what it wants.

i have been fixing repetitive things like this for an hour! it sucks.

oh well i need the experiance right? (i'll answer that) Right! :D

YoungBuck
Feb 13th, 2001, 08:51 PM
Forgive me if my technical grammar is not up to par in C++ but don't you have to have a function declaration if the function is written after the main() function, i.e.



#include <stdio.h>
#include <iostream.h>

const double Pi = 3.141592654;
char choice;

void LaSaCylinder(int radius, int hieght, double LA, double SA);

int main()
{
printf("a. Cylinder\n");
printf("b. Cone\n");
printf("c. Prism\n");
printf("d. Pyramid\n");
printf("--------------\n");
printf("x. Exit\n");

cin>>choice;

switch ( choice ){
case 'a':
LaSaCylinder();
break;
case 'x':
return 0;
};

};
//////////////////////////
//Cylinder Calculation ///
//////////////////////////
//LA = Lateral Area ///
//////////////////////////
//SA = Surface Area ///
//////////////////////////
void LaSaCylinder(int radius, int hieght, double LA, double SA);
{
cout << "What is the radius of the base?\n";
cin >> radius;
cout << "What is the height of the Cylinder?\n";
cin >> height;

LA = (2 * Pi * radius) * height;
SA = LA + (2 * (Pi * (radius^2)));

cout << LA << " is the Lateral area.\n";
cout << SA << " is the Surface area.\n";
};

HarryW
Feb 14th, 2001, 06:40 AM
Yeah, that too :)

factor777
Feb 14th, 2001, 01:30 PM
Wow i never knew that! well that really helps, no that more than helps, that broadens my horizons! :D

thanks YoungBuck and Harry.
:D :D :D :D :D :D :D :D :D :D

Wynd
Feb 14th, 2001, 04:49 PM
A thing I noticed is you spelled 'height' 'hieght', hope that helps.

Wynd
Feb 14th, 2001, 05:23 PM
I tried to make it work, this is what I did:


#include <iostream.h>

const double Pi = 3.1415926535897932384626433832795;
char choice;

void LaSaCylinder();

int main()
{
cout<<"a.\tCylinder\n";
cout<<"b.\tCone\n";
cout<<"c.\tPrism\n";
cout<<"d.\tPyramid\n";
cout<<"--------------\n";
cout<<"x.\tExit\n";

cin>>choice;

switch (choice)
{
case 'a':
LaSaCylinder();
break;
case 'x':
return 0;
}
}
//////////////////////////
//Cylinder Calculation ///
//////////////////////////
//LA = Lateral Area ///
//////////////////////////
//SA = Surface Area ///
//////////////////////////
void LaSaCylinder()
{
int radius, height, LA, SA;
cout << "What is the radius of the base?\n";
cin >> radius;
cout << "What is the height of the Cylinder?\n";
cin >> height;

LA = (2 * Pi * radius) * height;
SA = LA + (2 * (Pi * (radius^2)));

cout << LA << " is the Lateral area.\n";
cout << SA << " is the Surface area.\n";
}


I forgot to add, when you were writing the actual function (don't know what it's called) you put some semicolons between the parenthesis and the openign bracket, and that caused the old-style function thing. Hope this helps!