If statement only

Hello everyone! Please help me, what's wrong with my code?
I'm trying an if only statement with multiple conditions because that's what our prof instructed. I just need one output on that but when I run it all of the circumference, area, diameter, exit is included in the output. Please help me!



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
#include <iostream>
using namespace std;

int main()

{
	float Radius;
	cout<<"Enter Radius: ";
	cin>>Radius;
	
	//Menu
	char choice;
	
	cout<<"\t\t\t\t"<<"MENU"<<endl<<endl;
	cout<<"\t\t"<<"[C]"<<"\t"<<"Circumference of a Circle"<<endl;
	cout<<"\t\t"<<"[A]"<<"\t"<<"Area of a Circle"<<endl;
	cout<<"\t\t"<<"[D]"<<"\t"<<"Diameter of a Circle"<<endl;
	cout<<"\t\t"<<"[E]"<<"\t"<<"Exit"<<endl;
	cout<<"\t\t"<<"Enter your choice: ";
	cin>>choice;
	
	//If Statement
	char C, c, A, a, D, d, E, e;
	float pi, Circumference, Area, Diameter;
	pi= 3.142;
	
	
	if(choice== 'C' || "c"){
		Circumference = 2 * pi * Radius;
		cout<<endl;
		cout<<"\t\t"<<"The Circumference of a Circle is "<<Circumference;
}
	if(choice== 'A' || 'a'){
		Area = pi * (Radius*Radius);
		cout<<endl;
		cout<<"\t\t"<<"The Area of a Circle is "<<Area;
}
	if(choice== 'D' || 'd'){
		Diameter = 	2 * Radius;
		cout<<endl;
		cout<<"\t\t"<<"The Diameter of a Circle is "<<Diameter;
}
	if(choice== 'E' || 'e'){
		cout<<endl;
		cout<<"\t\t"<<"Exiting...";
		return 0;
	}
	
	return 0;
}
Last edited on
 
if(choice== 'C' || "c"){


You're misunderstanding how a condition is evaluated. This needs to be coded as

 
if(choice == 'C' || choice == "c"){


and the same for the other if statements.
Thank you so much! It works. I'm just new also to this forum so I didn't know how to use code tags. Can you help me with that also?
Edit: I just discovered it haha
Thank you again @lastchance and @seeplus
Last edited on
put the tags
[code]
and
[/code] 
around the code block.
Hello newbie prog10,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



Andy
Topic archived. No new replies allowed.