A novice programming question...

This is a discussion on A novice programming question... within the C Programming forums, part of the General Programming Boards category; I am trying to learn java. I know this place is for C but i really did not find other ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    55

    A novice programming question...

    I am trying to learn java. I know this place is for C but i really did not find other site to get help on java. So, i am hoping on you guys.

    Problem: If the value of temp is < than 300, then the program should conver that temp of temp into centigrade using convertToC function and then should ask user to enter the temp again. This should happen until the temp < 300. When temp is less greater that 300, the program should end.

    In this case i am basically trying to call the main function again when the user enters the value less the three. But, I am not being able to do so.
    Last edited by curious; 11-12-2008 at 06:11 PM. Reason: technical

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    67

    kpreston

    Try using a while loop:

    Code:
    while (fahrenheit > 300) {
        // Do stuff...
    }
    Don't forget to change fahrenheit every iteration.

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Put the prompt inside a loop and don't exit until you get the value you need. A do-while loop would work well.

    You need to use float or double data types, not int, otherwise, you won't get the proper result for an answer.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    55
    i tired while didn't work.
    Can you please write the whole main function?

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    55
    looping didn't work at all. I am getting into infinite loop.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by curious View Post
    looping didn't work at all. I am getting into infinite loop.
    You forgot to change fahrenheit every iteration. We warned you....

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    55
    that is what i am doing? i can't change fahrenheit inside the loop. the user should be able to do it.
    Last edited by curious; 11-12-2008 at 06:10 PM. Reason: technical reason

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The user should be able to do it, if you let them type something in. Since you don't, they can't. Maybe you should call nextInt again, so as to let them type something in.

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    55
    thank you, I was being foolish due to time pressure. I really appreciate your help .
    this is really good place to start programming.

    Thank you again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. Rtfm
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-13-2003, 05:19 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21