variable problem?

I have a problem with the second and third else if statements. It seems that they're using double air =(feet/1100) which is in the if statement instead of double water = (feet/4900) or double steel= (feet/16400). I'm not sure what the problem is really. I don't get an error. My testing number for feet 3500 and i get the same 3.18182 for the if statement and the else if statements.

help?

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 <iomanip>

using namespace std;

// no global variables

int main()
{

	char medium;
	double feet;
	
	cout << "Welcome to Sound Wave Calculator!\n\n";
	cout << "Select the medium the sound wave will travel through\n";
	cout << "A     Air\nW     Water\nS     Steel\n\n> ";

	cin >> medium;

	/* A = air
	W = water
	S = steel */

	
	if (medium == 'A'||'a')
	{
		cout << "How far will the sound wave travel (in feet)? ";
		cin >> feet;
		
		if (feet > 0)
		{
			double air = (feet / 1100);

			cout << "The sound wave will travel " << air << " seconds\n\n";
			cout << "Goodbye!\n";
		}
		else
			cout << "Distance cannot be negative. Aborting program.\nGoodbye!\n";
	}

	else if (medium == 'W'||'w')
	{
		cout << "How far will the sound wave travel (in feet)? ";
		cin >> feet;
		
		if (feet > 0)
		{
			double water = (feet / 4900);

			cout << "The sound wave will travel "<< water << " seconds\n\n";
			cout << "Goodbye!\n";
		}
		else
			cout << "Distance cannot be negative. Aborting program.\nGoodbye!\n";
	}

	else if (medium == 'S'||'s')
	{
		cout << "How far will the sound wave travel (in feet)? ";
		cin >> feet;
		
		if (feet > 0)
		{
			double steel = (feet / 16400);

			cout << "The sound wave will travel " << steel << " seconds\n\n";
			cout << "Goodbye!\n";
		}

		else
			cout << "Distance cannot be negative. Aborting program.\nGoodbye!\n";
	}

	else
		cout << "Illegal entry. Aborting program.\nGoodbye!\n";


	return 0;
}
(medium == 'A' || medium == 'a')

The way you wrote it, you were testing:

Is medium equal to 'A' ?
and
Is 'a' True/greater than 0 ?
Last edited on
Thank you so much Gaius that fixed it!

oh ok thanks for explaining too that helps me even more
Last edited on
Topic archived. No new replies allowed.