I have created a program that should roundup a number: Code: #include <iostream> using namespace std; int main() { double numr; int numroundup = numr; int numroundup1= numr + 1; cout<<"Input a number \n"; cin>>numr; if(numr >= .5){ cout<<"\nThe number is: \n"; cout<<numroundup1; cin.get(); } else if(numr < .5){ cout<<"The number is: "; cout<<numroundup; cin.get(); } return 0; } When I put the number it always says that the number is 1
The answer will ether be the 0 or 1. So what i think is happening is in the first IF, when it says cout<<numroundup1; it is printing 1, and that is because its value is 1. Back at the start of your program when you declare numroundup1 and you've got "= numr + 1" more or less since that at that time numr's value is 0 it really looks like this "int numroundup1 = 0 + 1" which will result in you getting 1 as the answer. What I think would be better is this: Code: #include <iostream> using namespace std; int main() { double numr; int numroundup = 1; int numroundup1; cout<<"Input a number \n"; cin>>numr; if(numr >= .5){ numroundup = numr + 1; cout<<"\nThe number is: \n"; cout<<numroundup1; cin.get(); } else if(numr < .5){ cout<<"The number is: "; cout<<numroundup; cin.get(); } return 0; } I edit it a bit there but what I did will not make you program work how you want it to. Firstly I think what you trying to do is get the program to judge(on the IF's) the number not by its' hole but by numbers after the dot, this however will not work. What it really is doing is(lets say you put in the number 2) hay 2 is bigger than .5 so I'll enter the if.
Actually you are right. If its more than .5 it enters the if statement. Is there a way a could fix this? Thank You, AssaultM16