c++ - Program must decide positive, negative, or zero -


i need desigen program must display positive, negative or 0 when user enter number function name called numtest. when enter number 0 still appears as, number negative. can me on this. thank you.

#include <iostream> using namespace std;   float numtest(float a, float b, float c) {     if(a>1)     return a;      if(b<1)     return b;      if(c=0)     return c; } int main() {     float num;     cout<<"please enter number";     cin>>num;      if(num>1)     cout<<"number positive";      if(num<1)     cout<<"number negative";      if(num=0)     cout<<"number zero";      return 0; } 

first of all, when checking equality must use == instead of =.the = sign assigns r.h.s. l.h.s. eg. c=0 changes value in c 0, instead should if(c==0).

now, if want check positive numbers, condition should if(num>0), , negative numbers, should if(num<0).

lastly, try use else if , else instead of 3 ifs.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -