Can't get my menu based application to accept choice

I can't get my menu driven app to accept my choice, so I can't even debug the rest of the program because it doesn't run, can someone find where I went wrong?

`

#include <iostream>
#include <string>



using namespace std;

double A_PI = 3.14159;

//function prototypes
void displayMenu();
int getChoice(int& choice);
void getRadius(int& radius);
double calcCircumference(int radius);
double calcArea(int radius);
int calcDiameter(int radius);
void displayTable();

int main()
{

int radius;
int choice = 0;

while (true)
{
//validate user input
while (choice < 1 || choice > 6)
{
cout << "Please enter a number between 1 and 5!";
system("cls");
displayMenu();
cout.flush();
getChoice(choice);

}

//call function getInput(plug in variable length and width here) //this is for reading length and width


switch (choice)
{

case 1:
getRadius(radius);
cout << "Radius is: " << radius << '\n';
break;

case 2:
cout << "Area is: " << calcArea(radius) << '\n';
break;

case 3:
cout << "Circumference is: " << calcCircumference(radius) << '\n';
break;

case 4:
cout << "Diameter is: " << calcDiameter(radius) << '\n';
break;

case 5:
displayTable();
break;

default:
return 0;
}

choice = 0;

}


}



void displayMenu()
{

cout << "CIRCLE APPLICATION\n\
___________________________\n\
1) Get Radius\n\
2) Calculate area\n\
3) Calculate Circumference\n\
4) Calculate Diameter\n\
5) Display Table\n\
6) Exit\n";


}

int getChoice(int& choice)
{
cout << "Please enter choice 1-6: ";

cin >> choice;

cin.ignore();

return choice;
}

void getRadius(int& radius)
{

while (radius > 1)
{
cout << "Type in the radius as an integer value: ";

cin >> radius;

cout << '\n';

if (radius < 1)
{
cout << "Incorrect value! Please try again! \n";
}
}

}

double calcCircumference(int radius)
{
return 2 * A_PI*radius;
}

double calcArea(int radius)
{
return A_PI * A_PI*radius;
}

int calcDiameter(int radius)
{
return 2 * radius;
}

void displayTable()
{
cout << "Radius\tCircumference\n";
cout << "____________________________________\n";

for (int i = 1; i<11; i++)
cout << i << '\t' << calcCircumference(i) << '\n';

}

`
Last edited on
char is an int, but 1 != '1'
your while loop to validate and switch both look for 1 not '1' (etc, other numbers too).

Topic archived. No new replies allowed.