How to know how many times double a is 2 times double b?

How to know how many times double a is equal to 2 times double b

So i want to calculate the amount of times the rainfall of a particular month is
more than 2 times the temperature of that same month. i've tried some idea's like the one below, with the amount of times that the rainfall is more than 2 times the temperature presented by 'x'. but that doesn't seems to work. Could someone 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
                            double T1, T2, T3, T4, T5;
                            double N1, N2, N3, N4, N5;

                            cout<<"Give the average temperature of january.\n";
                            cin>>T1;
                            cout<<"Give the average temperature of february.\n";
                            cin>>T2;
                            cout<<"Give the average temperature of march.\n";
                            cin>>T3;
                            cout<<"Give the average temperature of april.\n";
                            cin>>T4;
                            cout<<"Give the average temperature of may.\n";
                            cin>>T5;
                            cout<<"Give the average rainfall of january.\n";
                            cin>>N1;
                            cout<<"Give the average rainfall of fabruary.\n";
                            cin>>N2;
                            cout<<"Give the average rainfall of march.\n";
                            cin>>N3;
                            cout<<"Give the average rainfall of april.\n";
                            cin>>N4;
                            cout<<"Give the average rainfall of may.\n";
                            cin>>N5;



                            while(x > 0)
                                {
                                if(N1 >= 2*(T1) ) x + 1;

                                if(N2 >= 2*(T2) ) x + 1;

                                if(N3 >= 2*(T3) ) x + 1;

                                if(N4 >= 2*(T4) ) x + 1;

                                if(N5 >= 2*(T5) ) x + 1;
                                }

                            cout<<"The amount of wet months is now" << x <<" times.";

Why are your 'if' statements inside of a 'while' loop?
I don't know, i've just been trying some ways but i can't figure it out. Could you say how i'll have to do it to make it work?
If i understand you correctly i'm not sure what the issue is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

int main(){
	
	double januaryRainfall = 28.0;
	double januaryTemperature = 14.0;

	if (januaryRainfall >= (2 * januaryTemperature) )
	{
		std::cout << "rainfall is greater than twice temperature" << std::endl;
		// increment your count
	}
	else
	{
		std::cout << "Not!";
	}


	return 0;
}


Last edited on
Ty, but i want to know how many times the rainfall greater is than twice the temperature. so i added an int which presents the amounts of time the rainfall is greater than twice the temperature.

When i enter the rainfall and the temperature, my "wetMonths" stays on 0, but i am entering numbers so N >= 2T.


double T1, T2, T3, T4, T5;
double N1, N2, N3, N4, N5;
int wetMonths (0);

cout<<"Give the average temperature of january.\n";
cin>>T1;
cout<<"Give the average temperature of february.\n";
cin>>T2;
cout<<"Give the average temperature of march.\n";
cin>>T3;
cout<<"Give the average temperature of april.\n";
cin>>T4;
cout<<"Give the average temperature of may.\n";
cin>>T5;
cout<<"Give the average rainfall of january.\n";
cin>>N1;
cout<<"Give the average rainfall of fabruary.\n";
cin>>N2;
cout<<"Give the average rainfall of march.\n";
cin>>N3;
cout<<"Give the average rainfall of april.\n";
cin>>N4;
cout<<"Give the average rainfall of may.\n";
cin>>N5;


if(N1 >= (2*T1)) wetMonths + 1;

if(N2 >= (2*T2)) wetMonths + 1;

if(N3 >= (2*T3)) wetMonths + 1;

if(N4 >= (2*T4)) wetMonths + 1;

if(N5 >= (2*T5)) wetMonths + 1;


cout<<"The amount of wet months is now " << wetMonths <<" times.";
This statement wetMonths + 1; does not increment wetMonths. It makes a calculation and does nothing with the result. What you intend to say is either: wetMonths = wetMonths + 1; (which takes current value of wetMonths, adds one to it, and stores the new result back into wetMonths) or ++wetMonths; (which is an operator that does the same thing in more compact syntax.)
Last edited on
Topic archived. No new replies allowed.