C++ Assignment

Moderators: vinyard, KreepingMonkey

Message
Author
skaterbasist
C.S. Server Admin
Posts: 91
Joined: Fri Jul 13, 2007 11:43 pm
Contact:

Re: Call funtion from within the function?

#11 Post by skaterbasist » Mon Oct 01, 2007 10:05 pm

Vinyard wrote:
skaterbasist wrote:

Code: Select all

         //Return to original request
          System.out.print("Enter the height in integer Inches: ");
         integerInches=keyboard.nextInt();
Couldn't you just loop this by calling the same function over again?

Don't know if it's different for C++ or Java.
You're right... I didn't loop it properly. I modified my While statement to include [nest] both the If and Else statements with the boolean && operators. Here is the proper way to do it (loop). I tested it and now the loop works fine as everything else:

Code: Select all

//For the hell of it...
   import java.io.*;
   import java.util.*;
    class ForTheHellOfIt
   {
       public static void main (String args [])
      {
         int integerInches;
         int outputFeet;
         int outputInches;
         Scanner keyboard = new Scanner (System.in);
         System.out.print("Enter height in integer inches: ");
         integerInches = keyboard.nextInt();
         while (integerInches>0 || integerInches<=0)
         {
            if (integerInches>0)
            //Convert Interger Inches to Feet & Inches
            {
               outputFeet = integerInches / 12;
               outputInches = integerInches % 12;
            	//Display Integer Inches to Feet & Inches
               System.out.println("The height integer inches " +integerInches+ " in feet & inches is " +outputFeet+ " Feet and " +outputInches+" Inches");
               integerInches=keyboard.nextInt();
            }
				else
				{
					System.out.print("Must be a positive number: ");
					integerInches=keyboard.nextInt();
				}
			}
		}
	}
Image

User avatar
zero86ea
C.S. Server Admin
Posts: 318
Joined: Tue Jun 19, 2007 12:02 am
Contact:

Re: C++ Assignment

#12 Post by zero86ea » Mon Oct 01, 2007 10:56 pm

Not bad for a rookie skater :D
Image

Post Reply