© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
41 replies
Spekulant

❔ ✅ Inputing numbers

I want to write a short code that gets random input. It reads two numbers between random inputs.
using System;
namespace hello_wolrd;
class Program
{
    static void Main(string[] args)
    {

        int a = Inputer.ReadSymbol();
        int b = Inputer.ReadSymbol();
        Console.WriteLine(a + b);
    }
}

class Inputer
{
    public static int ReadSymbol()
    {
        int symbol = Console.Read();
        while ((symbol < '0') || (symbol > 9))
            symbol = Console.Read();
        int x = 0;

        while ((symbol >= '0') && (symbol <= '9'))
        {
            x = 10 * x + (symbol - '0');
            symbol = Console.Read();
        }


        return x;
    }
}
using System;
namespace hello_wolrd;
class Program
{
    static void Main(string[] args)
    {

        int a = Inputer.ReadSymbol();
        int b = Inputer.ReadSymbol();
        Console.WriteLine(a + b);
    }
}

class Inputer
{
    public static int ReadSymbol()
    {
        int symbol = Console.Read();
        while ((symbol < '0') || (symbol > 9))
            symbol = Console.Read();
        int x = 0;

        while ((symbol >= '0') && (symbol <= '9'))
        {
            x = 10 * x + (symbol - '0');
            symbol = Console.Read();
        }


        return x;
    }
}

im somewhere around here.. but i havent figured the minus numbers also... the input can be something like:
115
aaa-12

a
115
aaa-12

a
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ inputing numbers into list
C#CC# / help
3y ago
Only numbers
C#CC# / help
4y ago
arbitrary big numbers
C#CC# / help
3y ago
✅ List gets weird numbers
C#CC# / help
3y ago