What's error of my code? | SoloLearn: Learn to code for FREE!

-1

What's error of my code?

#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main() { cout<<endl<<"\nWeight:"; double weight; cin>>weight; cout<<endl<<"\nHeight:"; double height; cin>>height; double heightpow2=height*height; double bmi=weight/heightpow2; cout<<endl<<"\nBmi = "<<bmi; double hlr=rand()%17.9+12; if(bmi==hlr){ cout<<"\nWeight loss range"; } double hwr=rand()%24+18; if(bmi==hwr){ cout<<"\nHealthy weight range"; } return 0; }

2/24/2021 10:32:36 PM

Arash

17 Answers

New Answer

+5

like amost all languages: if (low <= bmi && bmi < high) == equals != different < lower than <= lower or equals > greater than >= greater or equals && logical AND || logical OR

+3

What are the errors you are getting from it?

+2

about int and double

+2

what are you meaning by using % operator, so?

+1

Arash the error says that you're trying to get remainder of integer division (% operator) with a decimal (double) as right operand (divisor)... maybe you're trying to get 17.9 percent of rand()? if so, you must do: rand()*17.9/100 ... and add 12, obviously: double hlr = rand()*17.9/100+12; edit: similar for hwr ;)

+1

No, I want to find a random number between the two number

+1

so, first you doesn't need random values, nor hlr and hwr... you just need to test if bmi is greater (or equal) than lowest boundary AND lowest than higest boundary ;)

0

With your solution, the errors disappear but the "if" command is no longer executed

0

what do you think doing with % initially? and what are you trying to achieve? as 'if' blocks have quite no chance to be executed, even if you provide the good calculation to get a decimal random value between two bounds ^^

0

What about "switch"?

0

what about explaining your purpose?

0

I named the variable under bmi in the code and now I want it to print a message if the value is between the two selected numbers

0

How?

0

You did type double value of int function. For Example: Int x = 28 double y = 17.9

-1

Tanks a lot

-1

#include <iostream> #inlcude <stdlib.h> #include <time.h> using namespace std; Int main() { double weight; cout << "Weight : "; cin >> weight; cout << endl; double height; cout << " Height "; cin >> height; cout << endl; double heightpow2 ; heightpow2 = height*height; cout << endl; double bmi ; bmi = weight/heightpow2; cout << "Bmi " << bmi << endl; double hlr; hlr = rand() % 17.9+12; If(bmi==hlr) { cout << "Weight loss range"; } double hwr; hwr = rand()%24+18; If(bmi==hwr) { cout << "Helthy weight range"; } system(" pause") return 0; } &&&&&: If it c++ : Do u include - <ctime>?? #include <ctime> "for rand" And Why u dont add : srand(0(time)) ?

-2

Айдын номе