Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Returning Back To The Beginning Of An If Statement
kvarnerexpress
post Sep 10 2005, 04:05 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



I have a bit of code. I am sooo close to figuring out. The only thing I need it to do, is return back to the beginning of the if statement after the new input is entered to determine of the new input meets the requirements. Here is my code:

Code:

CODE
int input() //request input from user
{
int size = 0, size_even = 0;

cout << " Please enter an odd number between 3 and 25: ";
cin >> size;
 
size_even = size % 2;
   
// if statement to determine if the number is between 3 and 25
if((size >= 3) && (size <= 25))
{
 // nested if statement to determine if the number is even or odd
 if(size_even == 0)
 {
  cout << " Invalid Entry! Please enter an ODD number between 3 and 25! ";
  cin >> size;
 }

 else
  cout << " This is an odd number. ";
}

else
 cout << " Invalid Entry! Please enter a number BETWEEN 3 and 25!";
 cin >> size;

return 0;
}



So for instance as it is now, if some one enters a number larger than 25, it prompts for a new number but that's it. I need it to prompt for the new number and then go back through the if statemtents to determine if it meets the conditions.

Thanks for anyhelp provided.

kvarnerexpress
Go to the top of the page
 
+Quote Post
sandbox
post Sep 10 2005, 05:08 PM
Post #2


Advanced Member
*******

Group: Members
Posts: 107
Joined: 9-September 05
From: Houston, TX USA
Member No.: 11,651



Um, is this your homework?!

Look up control structures in your book.

You'll learn a lot more if you figure it out yourself. Once you read the section on control structures the answer will be clear.

If you are still stuck you should probably email your prof instead of this forum. Your prof will be a better resource in the long run.

good luck
Go to the top of the page
 
+Quote Post
Poe
post Sep 16 2005, 08:18 AM
Post #3


Newbie
*

Group: Members
Posts: 2
Joined: 16-September 05
Member No.: 11,920



let me help him cheat

CODE

int input() //request input from user
{
   int size = 0, size_even = 0;
   bool bPass = false;
   do
   {
       cout << " Please enter an odd number between 3 and 25: ";
       cin >> size;            
       // if statement to determine if the number is between 3 and 25
       if((size >= 3) && (size <= 25))
       {
             size_even = size % 2;
            // nested if statement to determine if the number is even or odd
            if(size_even == 0)
           {
                  cout << " Invalid Entry! Please enter an ODD number between 3 to 25! ";
           }
           else
           {
                  cout << " This is an odd number. ";
                  bPass = true;
           }
       }
       else
              cout << " Invalid Entry! Please enter a number BETWEEN 3 and 25!";
   }while(!bPass)
   return 0;
}


Go to the top of the page
 
+Quote Post
Spectre
post Sep 17 2005, 05:59 PM
Post #4


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



I would do something like:

CODE
...
do {
  cout << " Please enter an odd number between 3 and 25: ";
  cin >> size;            
} while( size < 3 || size > 25 );
...


If this is your homework, I would suggest you do not ask for other people to solve it for you. You won't be able to post a message and wait for a reply on a forum during an exam.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Who Thinks Trap 17 Is Th Best Server?(6)
  2. What Website Do You Find Your Always Goin Back To?(77)
  3. Can You Go Back To High School?(15)
  4. Refresh Page After Back Button Hit(11)
  5. Java For The Beginning Programmer Ebook(4)
  6. Delete A Bunch Of Files Using Dos Statement(4)
  7. Would You Go On A Trip Into Deep Space?(29)
  8. Forgot The Wireless Wpa/wep(4)
  9. Beginning Java(10)
  10. Rpg Maker 2003 Shifted Game Screen(3)
  11. Bring Back The Ads(7)
  12. Rsc Is Back!(1)
  13. I Have A Dodgy Back... Need Some Tips Please.(12)
  14. Site Back Online, But....(20)
  15. Form Not Returning Correct Email Address(5)
  1. Back From First Year At College(2)
  2. Saint Michael Is Back And Spunkier Then Ever(8)
  3. Get Back Lots Of Disk Space(7)
  4. Sig Pop Rate Please(2)
  5. Bruney Could Be Back By Break(0)
  6. Help Me, Lost Skill Suddenly(2)
  7. In The Beginning Of Computer(4)
  8. Best Browser To Desighn Your Site To(16)
  9. Timer(6)
  10. I'm Back!(2)
  11. It Went Well For A While(5)
  12. I'm Back!(6)
  13. Can I Go Back To School?(5)


 



- Lo-Fi Version Time is now: 6th September 2008 - 08:01 PM