/* Cylinder calculation program that finds the volume and surface area
when given the diameter, the height, and value of pi. */
//Edit made, end block added
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main();
int end() {
char cont;
cout << "\n" << "Rerun cylcalc? y or n" << "\n";
cin >> cont;
if(cont='y'){
system("cls");
main(); }
elseif(cont='n'){
return 0;}
else {
cout << "\n" << "Not understood, use 'y' or 'n'";
return end(); }}
int main() {
double di, hi, pi, sa, vo, ra, ci;
// diameter
cout << "Diameter: ";
cin >> di;
cout << "\n" << "Height: ";
cin >> hi;
// pi
cout << "\n" << "Pi: ";
cin >> pi;
ra=di/2;
ci=ra*ra*pi;
// volume
vo=ci*hi;
cout << "\n" << "Volume= " << vo;
// surface area
sa=di*pi*hi+ci*2;
cout << "\n" << "Surface Area= " << sa << "\n";
system("pause");
return end();}
The if in function end() returns main() if given y, but it does that even if given n or an invalid character. It should end the program if given n, and restart end() if given an invalid character. What do I need to change to fix this?