Hello everyone. Home help = homework help :) can't change it now

I'm running into an error, expected initialize before "int menu()"

I have been playing around with it for a bit but I have not figured out how to get rid of the error.

When I think I got rid of the error, I ended up getting 40 new errors on the next compile. As of right now I am using quincy and with this code it is only showing the one error.

I'm aware there might actually be lots of more errors that are not showing up yet.


My assignment link is here:
http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm5.htm

Here is code:

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
#define PI 3.14159  //defined constant to be used in calculations
int choice, radius, length, width, height;
//int getValue(string prompt, int x, int y)


int  menu()
{
	int choice;
	cout << endl << endl << "******Surface Area Calculator******" << endl;
		cout << "1) Sphere " << endl;
		cout << "2) Cone " << endl;
		cout << "3) Reactangular Prism " << endl;
		cout << "4) Pyramid " << endl;
		cout << "5) Quit " << endl;
		cout << "***********************************" << endl;
		cin >> choice;
		while (choice<1||choice>5)
		{
		cout << "ERROR! Enter an integer value from 1 to 5" << endl;
		cin >> choice;
		}

return choice;	  	  
}

int getValue (string promt, int x, int y)
{
	int variable;
	cout << promt << "(" << x << "-" << y << ")";
	cin >> variable;
	while (variable < x || variable > y )
	{
	cout << "ERROR! Enter an integer value from " << x << " to " << y << endl;
	cin >> variable;
	}
	
return variable;
}

float calcSphere (int radius)
	{
	float SA;
	SA = (4 * PI * (radius * radius));	//calculations
	return SA;
	}

float calcCone (int radius)
	{
	float SA;
	SA = ( PI * radius * length ) + ( PI * (radius * radius));  //calculations
	return SA;
	}

float calcPrism(int radius)
	{
	float SA;
	SA = ( 2 * length * width ) + ( 2 * width * height ) + ( 2 * length * height );	//calculations
	return SA;
	}

float calcPyramid(int radius)
	{
	float SA;
	SA = ( 2 * length * height ) + (length * length);	//calculations
	return SA;
	}
	
int main()
{
int choice, radius, length, width, height;  //integers used to prevent user from using decimals, Boleen value declared
float SA;   
choice = menu();
	while (choice != 5)
	{
	if (choice == 1)
		{
		radius = getValue("Enter a radius: ",1,10);
		SA = CalcSphere(radius);
		cout << SA;          
		}
	if (choice == 2)
		{
		radius = getValue("Enter a radius: ",1,7);
		length = getValue("Enter a length: ",1,12);
		SA = CalcCone(radius);
		cout << SA;
		}
	if (choice == 3)
		{
		width = getValue("Enter a width: ",1,20);	 
		length = getValue("Enter a length: ",1,20);
		height = getValue("Enter a height: ",1,20);
		SA = CalcPrism(radius);
		cout << SA;
		} 
	if (choice == 4)
		{
		length = getValue("Enter a length: ",1,15);
		height = getValue("Enter a height: ",1,15);
		cout << SA;
		}
choice = menu();
}
}



//float calcSphere( int radius );

I don't see a problem. Maybe you should post the entire error, not paraphrase it.

Wonder if it has to do with using math.h instead of the C++ cmath. I doubt it, but cmath is the correct header.

Strange, I re-opened the program and the error is gone...very wierd.

The program actually appears to be running great.

The only problem I am having is my menu option 3 and 4 (prism and pyramid) keep returning zero for surface area.

And I'm not really sure why...

Changed a few letter cases that solved a few minor problems as well.

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
#define PI 3.14159  //defined constant to be used in calculations
int choice, radius, length, width, height;
//int getValue(string prompt, int x, int y)


int  menu()
{
	int choice;
	cout << endl << endl << "******Surface Area Calculator******" << endl;
		cout << "1) Sphere " << endl;
		cout << "2) Cone " << endl;
		cout << "3) Reactangular Prism " << endl;
		cout << "4) Pyramid " << endl;
		cout << "5) Quit " << endl;
		cout << "***********************************" << endl;
		cin >> choice;
		while (choice<1||choice>5)
		{
		cout << "ERROR! Enter an integer value from 1 to 5" << endl;
		cin >> choice;
		}

return choice;	  	  
}

int getValue (string promt, int x, int y)
{
	int variable;
	cout << promt << "(" << x << "-" << y << ")";
	cin >> variable;
	while (variable < x || variable > y )
	{
	cout << "ERROR! Enter an integer value from " << x << " to " << y << endl;
	cin >> variable;
	}
	
return variable;
}

float calcSphere (int radius)
	{
	float SA;
	SA = (4 * PI * (radius * radius));	//calculations
	return SA;
	}

float calcCone (int radius)
	{
	float SA;
	SA = ( PI * radius * length ) + ( PI * (radius * radius));  //calculations
	return SA;
	}

float calcPrism(int radius)
	{
	float SA;
	SA = ( 2 * length * width ) + ( 2 * width * height ) + ( 2 * length * height );	//calculations
	return SA;
	}

float calcPyramid(int radius)
	{
	float SA;
	SA = ( 2 * length * height ) + (length * length);	//calculations
	return SA;
	}
	
int main()
{
int choice, radius, length, width, height;  //integers used to prevent user from using decimals, Boleen value declared
float SA;   
choice = menu();
	while (choice != 5)
	{
	if (choice == 1)
		{
		radius = getValue("Enter a radius: ",1,10);
		SA = calcSphere(radius);
		cout << SA;          
		}
	if (choice == 2)
		{
		radius = getValue("Enter a radius: ",1,7);
		length = getValue("Enter a length: ",1,12);
		SA = calcCone(radius);
		cout << SA;
		}
	if (choice == 3)
		{
		width = getValue("Enter a width: ",1,20);	 
		length = getValue("Enter a length: ",1,20);
		height = getValue("Enter a height: ",1,20);
		SA = calcPrism(radius);
		cout << SA;
		} 
	if (choice == 4)
		{
		length = getValue("Enter a length: ",1,15);
		height = getValue("Enter a height: ",1,15);
		SA = calcPyramid(radius);
		cout << SA;
		}
choice = menu();
}
}

First of all you are passing radius to calcPrism and calcPyramid.

In those functions, the calculation is not based on radius.

The compiler fails to give any error , because you have the length,height and width defined as globals.

How would I pass height, length, width? Basically how would i achieve passing multiple things? Do i need multiple things?

I tried just using a comma, but came up with errors when I did.

you can use a function like

float calcPyramid(int length,int height)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.