Information from user in form of options

Can you please tell me how we can ask information from user in form of options, like Press 0 for "statement 1" Press 1 for "statement 2"

When user enters either 0 or 1, computer shows value according to that.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <cmath>
using namespace std;
float vel (float d,float ss1, float ss2, float w)
{float ac,v,n=0.018,r,dl=8,wpr,b=1.5,bs;
		if(d<=4.0)
		 	{ac=w*d;
		 	 wpr=(w+(2*d));
		 	}
		else if (d<=8.0)
			{ac=((w+bs*d)*d);
			 wpr= (w+ (2*d*sqrt(pow(ss1,2.0/3.0)+1)));
			}
		else
			{ac=(w+ss1*dl)*dl+(w+2*ss1*dl+2*b+ss2*(d-dl))*(d-dl);
			 wpr=(w+(2*dl*sqrt(1+pow(ss1,2.0))+(2*b)+(2*(d-dl)*sqrt(1+pow(ss2,2.0)))));
			}
		r=ac/wpr;
		v=(1/n)*sqrt(bs)*pow(r,2.0/3.0);
		return v;
}
int main ()
{float p,hg,h,d,w,qc,qr,bs,ac,v,wpr,s,r,ss1,ss2,dl,b=1.5,n,x,y,z;
cout<<"Enter Power Potential in MW = ";
cin>>p;
cout <<"Enter Gross Head in meters = ";
cin>>hg;
h=0.9*hg;
qr=(p*1000)/(9.81*0.80*h);
qc=0.0;
d=0.0;
while(qc<qr)
{
    d=d+0.005;
    w=d;
    if (d<=4.0)
{ ac=w*d;
}
else if (d<=8.0)
{ ac=w*(w+ss1*d);
}
else 
{ac=(w+ss1*dl)*dl+(w+2*ss1*dl+2*b+ss2*(d-dl)*(d-dl));
}
v=vel(d,ss1,ss2,w);
qc=ac*v;
}
cout<<"depth of the channel is "<<d<<endl;
cout<<"width of the channel is "<<w<<endl;
cout<<"disc harge value is"<<qc<<endl;

}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
cout<<"\nFor Lined Channel ..press 0\nFor Unlined Channel ..press 1\n";
cin>>x;
cout<<"\nFor Channel in Cutting ..press 0\nFor Channel in Filling ..press 1\n";
cin>>y;
cout<<"\nFor Power Channel ..press 0\nFor Head Race Channel ..press 1\n";
cin>>z;
	if (x==0 && y==0)
	{cout<<"Channel is Lined and Section is in Cutting";
	ss1=1, ss2=1;
	}
	else if (x==0 && y==1)
	{cout<<"Channel is Lined and Section is in Filling";
	ss1=1, ss2=1.5;
	}
	else if (x==1 && y==0)
	{cout<<"Channel is Unlined and Section is in Cutting";
	ss1=1, ss2=1.5;
	}
	else
	{cout<<"Channel is Unlined and Section is in Filling";
	ss1=1, ss2 =2;
	}
		if (z=0)
		{cout<<"Power Channel";
		bs=0.002;
		}
		else
		{cout<<"Head Race Channel";
		}



My motive is to merge both these programs.
You mean something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int option;
cout<<"1-For programmme A."<<endl<<"2-For programme B.";
cin>>option;

switch(option){
case 1:
//run programme A
break;
case 2:
//run programme B
break;
default:
cout<<"Bad Input";
}


Aceix.
Can you please make correction in this program and notify me about error ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <cmath>
using namespace std;
float vel (float, float);
int main ()
{
float p,hg,h,d,w,qc,qr,bs,ac,wpr,s,r,v,ss1,ss2,dl=8.0,b=1.5;
cout<<"Enter Power Potential in MW = ";
cin>>p;
cout <<"Enter Gross Head in meters = ";
cin>>hg;
float x,y,z;
cout<<"\nFor Lined Channel ..press 0\nFor Unlined Channel ..press 1\n";
cin>>x;
cout<<"\nFor Channel in Cutting ..press 2\nFor Channel in Filling ..press 3\n";
cin>>y;
cout<<"\nFor Power Channel ..press 4\nFor Head Race Channel ..press 5\n";
cin>>z;
	if (x==0 && y==0)
	{cout<<"Channel is Lined and Section is in Cutting\n";
	ss1=1, ss2=1;
	}
	else if (x==0 && y==1)
	{cout<<"Channel is Lined and Section is in Filling\n";
	ss1=1, ss2=1.5;
	}
	else if (x==1 && y==0)
	{cout<<"Channel is Unlined and Section is in Cutting\n";
	ss1=1, ss2=1.5;
	}
	else
	{cout<<"Channel is Unlined and Section is in Filling\n";
	ss1=1, ss2=2;
	}
		if (z=4)
		{cout<<"Power Channel\n";
		bs=(1/200);
		}
		else
		{cout<<"Head Race Channel";
		bs=(1/400);	
		}
h=0.9*hg;
qr=(p*1000)/(9.81*0.80*h);
qc=0.0;
d=0.0;
while(qc<qr)
{
    d=d+0.005;
  
    if (d<=4.0)
{ 	  w=d;
ac=w*d;
	wpr=(w+(2*d));
}
else if (d<=8.0)
{ 	w=2*d;
ac=w*(w+ss1*d);
	wpr= (w+ (2*d*sqrt(pow(ss1,2.0)+1)));
}
else 
{	w=2*d;
ac=(w+ss1*dl)*dl+(w+2*ss1*dl+2*b+ss2*(d-dl)*(d-dl));
	wpr=(w+(2*dl*sqrt(1+pow(ss1,2.0))+(2*b)+(2*(d-dl)*sqrt(1+pow(ss2,2.0)))));
}
		r=ac/wpr;
		v=vel(r,bs);
		qc=ac*v;		
}
cout<<"Depth of the channel = "<<d<<endl;
		cout<<"Width of the channel = "<<w<<endl;
		cout<<"Discharge of channel = "<<qc<<endl;
}
float vel (float r,float bs)
{
float n=0.018,vc;
vc=(1/n)*sqrt(bs)*pow(r,2.0/3.0);
return vc;
}



It is not showing last three cout statements
Topic archived. No new replies allowed.