Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:14:18+00:00 2026-05-28T17:14:18+00:00

Alright, nub question. I know. Basic response might be Convert.ToInt32(string); But naturally, C# does

  • 0

Alright, nub question. I know. Basic response might be

Convert.ToInt32(string);

But naturally, C# does every natural process to make sure just that doesn’t happen.

Here’s my code:

            while (true)
            {

                while (true)
                {
                    //ask for time
                    Console.WriteLine("What is the hour?");
                    Console.WriteLine();
                    string s = Console.ReadLine();
                    //convert input to int
                    YourTime.nHour = Convert.ToInt32(s);
                    //check to see if it's legal
                    if ((YourTime.nHour <= 12) || (YourTime.nHour > 0))
                    {
                        break;
                    }
                //etc etc code
                }
            }  

I want to make sure the input is an actual hour. When I run this code, it always labels the if() statement as “true” and breaks, even if I inputted something like -13 or 99.

I’m sure there’s a simple replacement for “Convert.ToInt32(s);”, but to be honest it seems like I’ve tried everything. I decided it would be best to follow step-by-step instructions from people who are aware of the code at hand.

[EDIT] – Wrong operator, not the conversion. Thanks to everyone who helped!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:14:19+00:00Added an answer on May 28, 2026 at 5:14 pm

    It’s your if statement that’s invalid, not the Convert.ToInt32

    if ((YourTime.nHour <= 12) || (YourTime.nHour > 0)) will always be true. I think you meant to do if ((YourTime.nHour <= 12) && (YourTime.nHour > 0))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright so I have recently made the decision to put every string in my
Alright, I'm trying to use the basic document.getElementsByTagName function, but each time I do,
Alright, I found out in this question that polling sockets does not scale, so
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright, quick question. A server is running in Eastern Time. PHP program needs to
Alright so im done doing pages with frames, and know i splitted up my
Alright so we had a problem recently In reporting services some of the String
Alright, so here is the property I have public List<String> names{ get{ lock(_names) return
Alright, so I think I'm pretty close to having what I need, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.