Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

calculator in cmd.exe, notepad++, code problem (C#)

calculator

  • Please log in to reply
22 replies to this topic

#13 Takashi

Takashi

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Learning:C#

Posted 16 September 2012 - 12:18 PM

I'm learning it at school and now I just re-make the programs we made at school.
We made 3 programs but I can't remeber the whole code from the third one (this is why I ask here in the forum).

Right now?
using System ;
namespace Add {
class Add {
static void Main (string[] args) {
int summand1 ;
int summand2 ;
int summe ;

Console.Write ("summand1: ") ;
summand1 = Convert.ToInt32 (Console.ReadLine () ) ;
Console.Write ("summand2: ") ;
summand2 = Convert.ToInt32 (Console.ReadLine () ) ;
Convert.ToString (Console.WriteLine (summe)) ;
}
}
}

  • 0

#14 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 16 September 2012 - 01:03 PM

I didn't tell you to delete summe = summand1 + summand2 line. I just tell you to switch it with Convert.ToString(Console.WriteLine(summe))
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#15 Takashi

Takashi

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Learning:C#

Posted 16 September 2012 - 01:14 PM

Ughh, sorry >.<.

Is this finally right now?
using System ;
namespace Add {
class Add {
static void Main (string[] args) {
int summand1 ;
int summand2 ;
int summe ;

Console.Write ("summand1: ") ;
summand1 = Convert.ToInt32 (Console.ReadLine () ) ;
Console.Write ("summand2: ") ;
summand2 = Convert.ToInt32 (Console.ReadLine () ) ;
summe = summand1 + summand2 ;
Convert.ToString (Console.WriteLine (summe)) ;
}
}
}

  • 0

#16 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 16 September 2012 - 01:25 PM

Yes. Now test it.
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#17 Takashi

Takashi

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Learning:C#

Posted 17 September 2012 - 04:29 AM

Doesn't work :/

http://i.imgur.com/hlq3q.jpg
  • 0

#18 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 17 September 2012 - 04:38 AM

I am sorry. Try with:

Console.WriteLine(Convert.ToString(summe));

I haven't work with console applications for a while so I did a mistake. Tell me if now it's working.
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#19 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 17 September 2012 - 05:38 AM

Can I ask why you are converting it to a string before writeline? Unless you are padding it, etc., there is no need.
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#20 Takashi

Takashi

    CC Newcomer

  • Member
  • PipPip
  • 12 posts
  • Learning:C#

Posted 17 September 2012 - 05:40 AM

I am sorry. Try with:

Console.WriteLine(Convert.ToString(summe));
I haven't work with console applications for a while so I did a mistake. Tell me if now it's working.

Thanks a lot.
But,
"summe: .." is not comming.
Only the result.

http://i.imgur.com/I0fdg.png

lespauled, sorry but I don't any clue yet. As I told you, we did it the first time in school, we haven't learned it much.
  • 0

#21 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 17 September 2012 - 06:03 AM

That's because you didn't add it to the writeline statement. You only put the value in the writeline. Add a console.write before the summe value, just like you did for the other variables.

A suggestion: Add an output variable of type string (I don't believe you've hit StringBuilder yet, correct?);

string output = summand1.ToString() + " + " + summand2.toString() + " = " + summe.ToString() ;

Then print output;
:
Console.WriteLine( output);
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#22 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 17 September 2012 - 06:49 AM

That's because you didn't add it to the writeline statement. You only put the value in the writeline. Add a console.write before the summe value, just like you did for the other variables.

A suggestion: Add an output variable of type string (I don't believe you've hit StringBuilder yet, correct?);

string output = summand1.ToString() + " + " + summand2.toString() + " = " + summe.ToString() ;

Then print output;
:
Console.WriteLine( output);

Why like that? He needs to learn manipulation of converting the data types.
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#23 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash

Posted 17 September 2012 - 08:04 AM

]Why like that? He needs to learn manipulation of converting the data types.


What are you talking about?
  • 0
My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download