#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
Arash17 Answers
New Answerlike amost all languages: if (low <= bmi && bmi < high) == equals != different < lower than <= lower or equals > greater than >= greater or equals && logical AND || logical OR
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 ;)
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 ;)
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 ^^
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
#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)) ?
SoloLearn Inc.
4 Embarcadero Center, Suite 1455Send us a message