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 8814649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:10:54+00:00 2026-06-14T04:10:54+00:00

I have this crazy idea, I would like a program to not execute anything

  • 0

I have this crazy idea, I would like a program to not execute anything if the wrong data is put into the console. Such as the alphabet, weird characters. All I want is decimal numbers and a period to be accepted. If the wrong data is typed in, I want the program to STAY there and do absolutely nothing after you hit enter.

My mindset thinks:

if (sum != decimal)
{
   // Don't do anything, just leave it as is. 
    code I have no clue about. 

}

Now, you must be thinking, you can’t use datatypes for an if statement! Maybe you can, but its not working for me. I’m sorry I’m a big noob.

try
{

    Console.WriteLine("Put in the price of the product");

    string input = Console.ReadLine();
    decimal sum = Convert.ToDecimal(input);

    if (sum <= 100)
    {
        decimal totalprice = sum * .90m;
        Console.WriteLine("Your final price is {0:0:00}", totalprice);

    }

}


catch
{

}

I was also thinking maybe a try and catch statement would work too, but again, I have no clue what to put in that either.

If your answers could be noob-safe and explained. (Because I want to learn the concept of how this stuff works) that would be nice.

A visual example:

stackoverflowimage

When you hit enter, nothing happens but when you put in the correct datatype, the program will continue.

  • 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-06-14T04:10:55+00:00Added an answer on June 14, 2026 at 4:10 am

    Datatypes are not written to console. Only strings could be retrieved from console input. What type has string "2" – decimal, int, byte, string? All you can do is try to parse some type from your input string:

    Int32.TryParse("2", out value)
    

    For your case:

    Console.WriteLine("Put in the price of the product");
    string input = Console.ReadLine();
    decimal sum;
    if (!Decimal.TryParse(input, out sum))
    {
        Console.WriteLine("Decimal number cannot be parsed from your input.");
        return;
    }
    
    if (sum <= 100)
        Console.WriteLine("Your final price is {0:0:00}", sum * 0.90M);
    

    UPDATE

    • Decimal.TryParse – Converts the string representation of a number to its Decimal equivalent. A return value indicates whether the conversion succeeded or failed. It does not throws an exception if conversion failed.
    • ! Operator – it is NOT operator. The logical negation operator (!) is a unary operator that negates its operand. It is defined for bool and returns true if and only if its operand is false.

    So if (!Decimal.TryParse(input, out sum)) verifies if conversion was NOT successful. Then I put a sample message for user and exited from method (if it was your Main method, then program will terminate. But this all is out of your initial question about parsing strings.

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

Sidebar

Related Questions

So I have this crazy idea to pass strings from an excel sheet into
This is driving me crazy. I have a PHP script that gets some data
Okay, this is just a crazy idea I have. Stack Overflow looks very structured
i have this crazy label for each time i create a migration that use
Any regex gurus around here? its driving me crazy. Say I have this string:
This is crazy, I have been trying for hours to get this to work.
I'm getting crazy with this problem: I have got some Oracle SQL-Reports to redesign
This has been driving me crazy for the past few minutes I have a
This is driving me crazy. I have a very simple user control: public int?
This is driving me crazy and I can't find the answer anywhere. I have

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.