-
Plz help this newbie
Hi guys I've come back for more helps :D gotta love this forum
Today i was trying to create my second program and i was so glad that
almost half of them work the first time i run it
My questions is that i do not get why the output of this program for monthly payment is off from what i had in ths book, can you guys help me figures this out?thnx
-
What was the ouput in the book?
-
Isn't that more C-programming rather than C++? Anyway,
>> scanf("%f",&rate);{
why the '{'? That should go after the if statement, and because there is only one thing being 'iffed', you don't need them, same with the else if's. I have to run to work, cycle, so at the moment I can't give any more info.
-
Yet it is good practice to use
Code:
if ( x != value )
{
//code here
}
rather than using
Code:
if ( x != value )
//single line of code here
Think about how the two work, and see the possible problems that could be caused by using the 2nd choice. After thinking about it, it is clearly a better Idea to use choice number one for code safety
-
There's nothing pertaining to "code safety" that I can see. I don't see any problem either that the 2nd choice can cause.
Can you elaborate?
-
lets see...
alright in
Code:
if ( x != var ) {
//code here
}
//continue main here
assuming you add a line of code to the if statement brackets are already there no problem.
yet in
Code:
if ( x != var )
// if code here
// main code here
if you add a line of code to the if statement and perhaps forget to add the brackets or thought they were already there then you code will run the function or whatever either way. So dependant on situation this could have a minor effect on your program or it might cause a major error. The likeliness of someone making such a mistake may be slim but better safe than sorry right?
I wasnt saying that one is particularly better but it just seem as though using brackets with if statements is a safer way to go
-
sorry went to the wrong board without realizing it