Thursday, July 30, 2009

Whats wrong with my c++ program?

ok so this is my program, I want to know why it doesnt work with out using all the return 0's???





#include %26lt;iostream%26gt;


using namespace std;





int main ()


{


double num1;


double num2;


double num3;





cout %26lt;%26lt; "Enter three numbers =%26gt; ";


cin %26gt;%26gt; num1;


cin %26gt;%26gt; num2;


cin %26gt;%26gt; num3;





if ((num1 %26gt; num2) %26amp;%26amp; (num2 %26gt; num3))





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num1 %26lt;%26lt; num2 %26lt;%26lt; num3 %26lt;%26lt; endl;


return 0;


}





else if ((num1 %26gt; num3) %26amp;%26amp; (num3 %26gt; num2))





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num2 %26lt;%26lt; num3 %26lt;%26lt; num1 %26lt;%26lt; endl;


return 0;


}





else if ((num2 %26gt; num3) %26amp;%26amp; (num3 %26gt; num1))





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num2 %26lt;%26lt; num3 %26lt;%26lt; num1 %26lt;%26lt; endl;


return 0;


}





else if ((num3 %26gt; num2) %26amp;%26amp; (num2 %26gt; num1))





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num3 %26lt;%26lt; num2 %26lt;%26lt; num1 %26lt;%26lt; endl;


return 0;


}





else if ((num3 %26gt; num1) %26amp;%26amp; (num1 %26gt; num2))





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num3 %26lt;%26lt; num1 %26lt;%26lt; num2 %26lt;%26lt; endl;


return 0;


}





else if ((num2 %26gt; num1) %26amp;%26amp; (num1 %26gt; num3));





{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num2 %26lt;%26lt; num1 %26lt;%26lt; num3 %26lt;%26lt; endl;


}





return 0;


}

Whats wrong with my c++ program?
For your descending order thing, you don't even need to say int main(), just say main(). Doing so you won't even need to return anything and can therefore take out all your return statements..





For your grade program, don't check from A to F. Check from F to A, otherwise anything higher than F will always be F.
Reply:Its been a little while since I programmed in C++ but my guess is its the





int main()





if you don't want to return anything, replace it with void main()





See if that helps.
Reply:hi,


How if statement return value,function only return value,so that it displays error,becoz if statement can't return value..
Reply:else


{


if ......


}








edit:


else


{


if ((num1 %26gt; num3) %26amp;%26amp; (num3 %26gt; num2))


{


cout %26lt;%26lt; "Descending order =%26gt; " %26lt;%26lt; num2 %26lt;%26lt; num3 %26lt;%26lt; num1 %26lt;%26lt; endl;


return 0;


}


}





everytime


No comments:

Post a Comment