Thread: Plz help this newbie

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    4

    Plz help this newbie

    Hi guys I've come back for more helps 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

  2. #2
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31
    What was the ouput in the book?

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    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.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    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

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    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?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    673

    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

  7. #7
    Registered User
    Join Date
    Jul 2006
    Posts
    4
    sorry went to the wrong board without realizing it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie c programmer need assistance plz...
    By Nexus-ZERO in forum C Programming
    Replies: 17
    Last Post: 12-27-2007, 04:05 PM
  2. Newbie needs help plz
    By boffinson in forum C++ Programming
    Replies: 22
    Last Post: 07-29-2006, 03:25 AM
  3. im newbie to opengl, help plz
    By NecroFromHell in forum C++ Programming
    Replies: 4
    Last Post: 05-14-2006, 08:24 PM
  4. newbie reading a file..how? plz help
    By iori in forum C Programming
    Replies: 3
    Last Post: 04-09-2003, 03:58 PM
  5. HI .. newbie to the board... need some help plz
    By Arwen27 in forum C Programming
    Replies: 3
    Last Post: 04-28-2002, 07:27 AM