Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# int conversion.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Sat Oct 25, 2008 9:47 am    Post subject: C# int conversion. Reply with quote

Code:

            Console.WriteLine(
                "            *****************************************************"
                );
            Console.WriteLine(
                "            *                [Stefon]'s Addition                *"               
                );
            Console.WriteLine(
                "            *                    Calculator                     *"
                );
            Console.WriteLine(
                "            *****************************************************"
                );
            Console.WriteLine("");
            Console.WriteLine("Please enter two numbers that will be added together");
            Console.WriteLine(" ");
            Console.Write("Number 1: ");
            string num1 = Console.ReadLine();
            Console.Write("Number 2: ");
            string num2 = Console.ReadLine();
            string sum = num1 + num2;
            Console.WriteLine(sum);
            Console.ReadLine();


If you ran this code and the two numbers you entered were "4" and "5" the output would be "45". The output I want is "9". I know what I got to do. I got to get num1 and num2 and sum to be a int. But the contents of a Console.ReadLine(); cannot be an int. So I have it as as string right now.

So how do I convert my strings into an int.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Oct 25, 2008 9:50 am    Post subject: Reply with quote

int nNum1 = num1.ToInt32();

??

_________________
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Sat Oct 25, 2008 9:58 am    Post subject: Reply with quote

lurc wrote:
int nNum1 = num1.ToInt32();

??


Nope.
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Sat Oct 25, 2008 11:03 am    Post subject: Reply with quote

Code:
 int sum = Convert.ToInt32(num1) +  Convert.ToInt32(num2);
Console.WriteLine(Convert.ToString(sum));
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sat Oct 25, 2008 11:42 am    Post subject: Reply with quote

A simple google search would have sufficed. Rolling Eyes ToDecimal(String) or Int32.Parse(input); or ToUInt32(String)
_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Sat Oct 25, 2008 11:48 am    Post subject: Reply with quote

HolyBlah wrote:
Code:
 int sum = Convert.ToInt32(num1) +  Convert.ToInt32(num2);
Console.WriteLine(Convert.ToString(sum));


Thanks it worked.
+REP
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Oct 25, 2008 12:00 pm    Post subject: Reply with quote

Code:
string num1 = Console.ReadLine();


Why do you read is as string ???
Why not integer??
Back to top
View user's profile Send private message
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Sat Oct 25, 2008 12:04 pm    Post subject: Reply with quote

blackmorpheus wrote:
Code:
string num1 = Console.ReadLine();


Why do you read is as string ???
Why not integer??

It wouldnt let me do

int num1 = Console.ReadLine();
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Oct 25, 2008 12:06 pm    Post subject: Reply with quote

but it will let you do it like this
Code:

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

_________________
Stylo
Back to top
View user's profile Send private message
Frostbyt3
Master Cheater
Reputation: 0

Joined: 07 Jan 2008
Posts: 323
Location: Australia

PostPosted: Sat Oct 25, 2008 5:04 pm    Post subject: Reply with quote

Uhhh...


Code:
int1 = Console.Read();


Was it that hard?
Back to top
View user's profile Send private message MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sat Oct 25, 2008 5:34 pm    Post subject: Reply with quote

Frostbyt3 wrote:
Uhhh...


Code:
int1 = Console.Read();


Was it that hard?


Not quite.

Console.Read() returns one char, and it'll return the ASCII value, not the actual integer that the symbol represents.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Frostbyt3
Master Cheater
Reputation: 0

Joined: 07 Jan 2008
Posts: 323
Location: Australia

PostPosted: Sat Oct 25, 2008 5:51 pm    Post subject: Reply with quote

Really? Mine's returning the numerical value..

If i type in 1337, it doesn't come out as 49(ASCII for 1), it comes out 1337.

Weird.
Back to top
View user's profile Send private message MSN Messenger
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Sat Oct 25, 2008 7:45 pm    Post subject: Reply with quote

int.parse(<string here>);

thats the way i mainly use

either that or

Convert.ToInt32(<string>);

_________________
Back to top
View user's profile Send private message AIM Address
OSIRIS
Grandmaster Cheater
Reputation: 0

Joined: 27 Aug 2006
Posts: 654

PostPosted: Sat Oct 25, 2008 7:47 pm    Post subject: Reply with quote

yoyonerd wrote:
int.parse(<string here>);

thats the way i mainly use

either that or

Convert.ToInt32(<string>);


I liked Convert.ToInt32(<string>);
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Sun Oct 26, 2008 12:06 am    Post subject: Reply with quote

both work, so, whatever you're more comfotable with really
_________________
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites