first of here is how the part that asks if he wants to restart should be written:
Code:
std::cout<<"\nall done?";
char yn;
std::cin>>yn;
if (yn=='n' || yn == 'N')
goto z;
else
return 0;
second the use of goto is not advisable, it generally thought of to be a bad thing in C++. A better way to write you program would be something like this:
Code:
#include<iostream>
int main()
{
int area, volume, height, width, length, sphere, circ, vols, pi, y, n ;
bool finished = true; // ADDED THIS: will hold true if finished else it will hold false
char temp = '\0'; // Used for user input, set to empty.
pi = 3.14159265;
do
{
std::cout<<"\nDo you wish to calculate Area or Volume or vol of Sphere?(A/V/S)";
char avs;
std::cin>>avs;
if (avs == 'a')
{
//input and calculate area
std::cout<<"\ninput width in inches:";
std::cin>>width;
std::cout<<"\ninput length in inches:";
std::cin>>length;
area=length*width;
std::cout<<"\narea is:";
std::cout<<area;
std::cout<<" Square Inches";
}
else if (avs == 'v')
{
//input and calculate volume
std::cout<<"\ninput width in inches:";
std::cin>>width;
std::cout<<"\ninput height in inches:";
std::cin>>height;
std::cout<<"\ninput length in inches:";
std::cin>>length;
volume=height*width*length;
std::cout<<"\nvolume is:";
std::cout<<volume;
std::cout<< " Cubic Inches";
}
else if (avs == 's')
{ //input and calculate circumfrence
std::cout<<"\n input diameter/2 or radius";
std::cin>>sphere;
vols = 4*pi*(sphere*sphere);
circ = (2*sphere)*pi;
std::cout<<"\narea is:";
std::cout<<vols;
std::cout<< "Cubic inches";
std::cout<<"\nby the way the circumfrence is";
std::cout<<circ;
std::cout<< " Inches";
}
// Does the user wish to continue or quit?
cout << "Do you want to quit? (Y)es or (N)o?";
cin >> temp;
if(temp == 'n' || temp == 'N')
done = false;
else if(temp == 'y' || temp == 'Y')
done = true;
else
{
cout << "Invalid Input...";
return 0;
}
} while(!done)
return 0;
}
further more, i didn't do it in the above code, but always initialize your variables when you create them.