Apr 24, 2014 at 3:44pm UTC
#include <iostream>
#include <math.h>
using namespace std;
void menu();
void simplemenu();
void trigmenu();
void areamenu();
void trapazoidpic();
double power(double numberone, double numbertwo);
double factoring(double number);
double meanvalue(double numnum, int numf);
double sqrtt(double number);
double trig();
double absolute(double number);
double subtract(double numberone, double numbertwo);
double times(double numberone, double numbertwo);
double add(double numberone, double numbertwo);
double divide(double numberone, double numbertwo);
double circle(double rad);
double traingle(double base, double height);
double square(double side);
double rectangle(double height, double length);
double trapazoid(double base1, double base2, double height);
double hexagon(double side);
int main ()
{
int descision=0, smdescision=0, amdescision=0, againdescision=0;
double number=0, numberone=0, numbertwo=0;
redescision:
cout<<"This program is a calculator.\nPlease chose an option from below."<<endl;
back:
menu();
cout<<"Descision: ";
cin>>descision;
cout<<endl;
if(descision!=0 && descision!=1 && descision!=2 && descision!=3 && descision!=4 && descision!=5 && descision!=6 && descision!=7 && descision!=8)
{
cout<<"Please enter a number between 0 and 8!"<<endl;
goto redescision;
}
switch(descision)
{
case 0:
{
cout<<"Have a nice day!";
break;
}
case 1:
{
cout<<"Absolute Value"<<endl;
cout<<"Number: ";
cin>>number;
cout<<endl;
absolute(number);
cout<<"The absolute value of "<<number<<" is: "<<absolute(number)<<endl;
goto again;
}
......
case 6:
{
int numnum=0, numf, num=0;
cout<<"Mean Value"<<endl;
cout<<"Number of numbers: ";
cin>>numnum;
cout<<"Please enter the numbers: ";
for(int x=0; x=numnum; x++)
{
cin>>num;
numf[x]=num; <----Error here
}
meanvalue(numnum, numf);
cout<<"The mean value is: "<<meanvalue(numnum, numf)<<endl;
}
case 7:
{
cout<<"Square Root"<<endl;
cout<<"Number: ";
cin>>number;
numberone=number;
sqrtt(number);
cout<<"The Square Root of "<<numberone<<" is: "<<sqrtt(number);
goto again;
}
}
again:
cout<<endl;
cout<<"Run again? (1=Y||2=No): ";
cin>>againdescision;
if(againdescision=1)
goto back;
else
cout<<"Have a nice day!! :)";
return 0;
}
void menu()
{
cout<<"0. Quit"<<endl;
cout<<"1. Absolute Value"<<endl;
cout<<"2. +, -, /, *"<<endl;
cout<<"3. Power"<<endl;
cout<<"4. Factor"<<endl;
cout<<"5. Area"<<endl;
cout<<"6. Mean Value"<<endl;
cout<<"7. Square Root"<<endl;
//cout<<"8. Trig Functions"<<endl;
}
.......
double traingle(double base, double height) //triangle function
{
return(base*height*.5);
}
double square(double side) //square function
{
return(side*side*1.0);
}
double rectangle(double height, double length) //ractangle function
{
return(height*length*1.0);
}
double trapazoid(double base1, double base2, double height) //trapazoid function
{
return(.5*height*(base1+base2));
}
double hexagon(double side) //hexagon function
{
return(((3*(sqrt(3)))/2)*side*side*1.0); //sqrt() calculates the square root of a number
} //equation: ((3*sqrt(3))/2)*side*side side=length of one of the 6 sides
double meanvalue(double numnum, int numf)
{
int numberr=0;
for(int x=0; x=numnum; x++)
{
numberr=numf[x]+numberr; <---Error here
}
return(numberr/numnum*1.0);
}
double sqrtt(double number)
{
return(sqrt(number));
}
Apr 24, 2014 at 3:45pm UTC
Please wrap the code tags around your code to make it readable.
Edit: You really should avoid ever using Goto
Last edited on Apr 24, 2014 at 3:47pm UTC
Apr 24, 2014 at 3:55pm UTC
1 2 3 4 5 6 7 8 9 10 11 12
case 6:
{
int numnum=0, numf, num=0; //numf is defined as int type variable, not an array
cout<<"Mean Value" <<endl;
cout<<"Number of numbers: " ;
cin>>numnum;
cout<<"Please enter the numbers: " ;
for (int x=0; x=numnum; x++) // did you mean == numnum?
{
cin>>num;
numf[x]=num; <Error here //you're trying to use a subscript on a regular int
}
Last edited on Apr 24, 2014 at 3:57pm UTC