Jump to content

ascii output with int

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello,

I am having a problem with my code, still a newb sorry, but wondering what is the problem, it always shows up as 10 when the user should input name and number (it can be any number) and the output of it, the name is fine and the number is not, i know it has to do with ASCII however i dont know howto get around it, any ideas? here is the code below if you can just re-write it to correct it that would be great thanks


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            int myinteger;

            string mystring;


            Console.WriteLine("please enter your first name");

            mystring = Console.ReadLine();

            Console.WriteLine("your name is " + mystring);

            Console.Read();

            Console.WriteLine("please enter a number");

            myinteger = Convert.ToInt32(Console.Read());

            Console.WriteLine("you have entered " + myinteger);

            Console.WriteLine("your name is " + mystring + " and the number you picked is " + myinteger);

            Console.Read();

        }

    }

}



#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
At least you've posted in the right place this time. :)

You are using Convert.ToInt32(). Use int.Parse() instead.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Hello Xav
Thanks for the info, however it says no overload for method "parse" takes "0" arguments. what should i put in () on int.parse()?

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
The same argument as you used for the other method. Just rename the method.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
Siten0308

Siten0308

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 302 posts
Sweet it works thanks!!

here is the code below:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            int myinteger;

            string mystring;


            Console.WriteLine("please enter your first name");

            mystring = Console.ReadLine();

            Console.WriteLine("your name is " + mystring);

            Console.WriteLine("please enter a number");

            myinteger = int.Parse(Console.ReadLine());

            Console.WriteLine("you have entered " + myinteger);

            Console.WriteLine("your name is " + mystring + " and the number you picked is " + myinteger);

            Console.ReadKey();

        }

    }

}



#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
You're very welcome. :)
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums