Creating a Menu... :: Forum

Start Date Last Update Igniter Last Update By Status
2:30am on Wednesday 17th July 2013 11 years ago

sinha2366

sinha2366




sinha2366
Here's what I need help with:

I have a program here that calculates the midpoint and the distance of two given points.

#include
#include
#include

using namespace std;

int main ()

{
double x_coordinate1;
double y_coordinate1;
double x_coordinate2;
double y_coordinate2;
double mid_x;
double mid_y;
double c_pro;
char t;
char answer; //User's answer.



cout << "nttWelcome to the 2D Midpoint Program!!!nn";


answer = 'y';
while (tolower(answer) != 'n')
{
cout << "nttWhere is your first point?nn";
cin >> ws;
if ( cin.peek() != '(')
{

cout <<"nYou were missing the open parenthesis before the x coordinate!nn";
}
else
{
cin >>t;
}
cin >> x_coordinate1;

cin >> ws;
if ( cin.peek() != ',')
{

cout <<"nYou were missing the comma between to seperate coordinates!nn";
}
else
{
cin >>t;
}
cin>> y_coordinate1;

while (cin.peek() != 'n' &&
isspace(cin.peek()))
{
cin.ignore();
}
if ( cin.peek() != ')')
{

cout <<"nYou were missing the close parenthesis after the y coordinate!nn";
}
else
{
cin>>t;
}


cout << "nttWhere is your second point?nn";

cin >> ws;
if ( cin.peek() != '(')
{

cout <<"nYou were missing the open parenthesis before the x coordinate!nn";
}
else
{
cin >>t;
}
cin >> x_coordinate2;

cin >> ws;
if ( cin.peek() != ',')
{

cout <<"nYou were missing the comma between to seperate coordinates!nn";
}
else
{
cin >>t;
}
cin>> y_coordinate2;

while (cin.peek() != 'n' &&
isspace(cin.peek()))
{
cin.ignore();
}
if ( cin.peek() != ')')
{

cout <<"nYou were missing the close parenthesis after the y coordinate!nn";
}
else
{
cin>>t;
}


cout << "nttThank you!! Calculating... Done.nn";
mid_x = (x_coordinate1 + x_coordinate2)/2;
mid_y = (y_coordinate1 + y_coordinate2)/2;

c_pro = (sqrt((x_coordinate2 - x_coordinate1)* (x_coordinate2 - x_coordinate1)) + ((y_coordinate2 - y_coordinate1)* (y_coordinate2 - y_coordinate1)));



cout << "n(" << x_coordinate1<< ","<< y_coordinate1<<") is "<
cout << "nThe midpoint of the line segment from ("<< x_coordinate1
<< ","<< y_coordinate1<<") and ("<< x_coordinate2<<","
<< y_coordinate2<<") is ("<
cout << "nDo you want to calculate another midpoint?" "y/n?";
cin >> answer;
cin.ignore(INT_MAX,'n');
}
cout << "nttThank you for using the 2PP!!nn";

cout << "nttEndeavor to have a day...!nn";

return 0;
}




How can I add a menu to this program that prompts the user and asks for what the user needs specifically?
I want it to look something like this:

Welcome to the Point Menu Program!!!

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: n

I'm sorry, that choice is invalid!

Please try to read/type more carefully next time...

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: m

Please enter two points before choosing this option!

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: D

Please enter two points before choosing this option!

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: e

1) enter First point
2) enter Second point
3) Nevermind...

Choice: e

I'm sorry, that choice is invalid!

Please try to read/type more carefully next time...

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: E

1) enter First point
2) enter Second point
3) Nevermind...

Choice: F

Where is your first point? (3.4, 12.2)

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: 3

Please enter two points before choosing this option!

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: 1

1) enter First point
2) enter Second point
3) Nevermind...

Choice: 1

Where is your first point? (13.4, 12.2)

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: M

Please enter two points before choosing this option!

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: E

1) enter First point
2) enter Second point
3) Nevermind...

Choice: s

Where is your second point? (3.4, 12.2)

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: M

The midpoint of the line segment from (13.4, 12.2) to
(3.4, 12.2) is (8.4, 12.2).

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: d

(13.4, 12.2) is 10 units away from (3.4, 12.2).

1) Enter point
2) calculate Distance between two points
3) calculate Midpoint of two points
4) Quit

Choice: q


NOTICE how the case sensative works.

Your help is greatly appreciated.

Thank you

Please login to post your reply!
 

Login

Username:
Password:
Don't have an account?
Register here
Register

Subscribe Youtube



Network DigitalStage.org


Some interesting stuffs