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

#1 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 04:33 AM

Hello dear Community.

So basically I want to create a calculator (with + only).
I'm a beginner in programming and haven't worked so much with C# yet.

Here is the code.. (in Notepad++)
using System ;
namespace Add {
class Add {
static void Main (string[] args) {
int summand1 ;
int summand2 ;
int summe ;
summe = summand1 + summand2 ;
Console.WriteLine ("summand1: ") ;
summand1 = Convert.ToInt32 (Console.ReadLine () ) ;
Console.WriteLine ("summand2 ") ;
summand2 = Convert.ToInt32 (Console.ReadLine () ) ;
Console.WriteLine (summe) ;
}
}
}

What is wrong with it?
cmd.exe doesn't show me what I want.

It should normally show me

Summand1: *here I type the first integer*
Then Summand2: *here I type the second integer*
then == and after the result.
We actually made that in school but I can't properly remember how it worked..

Any help is much appreciated.
Summand = addend
Summe = sum
  • 0

#2 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 - 05:41 AM

You have made sumation of command1 and command2 before you enter the values in them. Try to make sumation after you enter both values.
  • 1

Microsoft Student Partner, Microsoft Certified Professional


#3 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 10:49 AM

You have made sumation of command1 and command2 before you enter the values in them. Try to make sumation after you enter both values.

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

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

summe = summand1 + summand2 ;
}
}
}
Like this?
I do not properly understand what you want to tell me.

I don't need any value, the values well be typed manually in cmd.exe and then it will tell me the result.

Edit: owwwwwww yeah, thank you.
But now I got 2 problems, why isn't it in the same line?
Pic: http://i.imgur.com/NcRub.jpg
And why doesn't it give me the result?
http://imgur.com/hyT45

The code is:
using System ;
namespace Add {
class Add {
static void Main (string[] args) {
int summand1 ;
int summand2 ;
int summe ;
 
Console.WriteLine ("summand1: ") ;
summand1 = Convert.ToInt32 (Console.ReadLine () ) ;
Console.WriteLine ("summand2: ") ;
summand2 = Convert.ToInt32 (Console.ReadLine () ) ;
summe = summand1 + summand2 ;
}
}
}

Also, why do I need to type "summe = summand1 + summand2" in the line after Console, Convert.. etc. and not before?
Sorry for the questions but I'm a beginner and do not really know this things (yet).
  • 0

#4 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 - 10:53 AM

Yes this is what I am telling you. It doesn't matter where are you running your code it's still the same. This problem is only a logical thing. How can you calculate some result if you don't have any parameters to calculate? First you need to enter those values so you will be able to do calculations on them.
  • 1

Microsoft Student Partner, Microsoft Certified Professional


#5 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 11:00 AM

Yes this is what I am telling you. It doesn't matter where are you running your code it's still the same. This problem is only a logical thing. How can you calculate some result if you don't have any parameters to calculate? First you need to enter those values so you will be able to do calculations on them.

Sorry but I don't understand.
In school we didn't enter any value in the code, we simply left it blank (as u can see in my code . "summand1:*blank* ".
We entered values only in cmd.exe.. like in this pic: http://imgur.com/hyT45
The only difference was that the value we wrote in cmd.exe, was in the same line as summand1/2 and it showed the result.

Maybe I missunderstand your reply.. sorry if yes.
  • 0

#6 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 - 11:07 AM

Yes you missunderstand me. I never tell you to enter values within your code. You are entering your values in CMD. Have you tried your new source code?
  • 1

Microsoft Student Partner, Microsoft Certified Professional


#7 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 11:10 AM

Yeap, if you mean the last one I posted.

This comes:

http://i.imgur.com/Qcgp4.jpg

Edit: Found out how the value I type in stays in the same line as summand1/2. But not how to get the result.
  • 0

#8 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 - 11:44 AM

And where is your output line? You forget to use final WriteLine
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#9 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 11:48 AM

May you tell me what to write? It would be more easier for me to get everything if I see it.
  • 0

#10 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 - 12:03 PM


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

This is what you need at the end. Have you ever programmed before?
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#11 Takashi

Takashi

    CC Newcomer

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

Posted 16 September 2012 - 12:05 PM

Convert.ToString(Console.WriteLine(summe));
This is what you need at the end. Have you ever programmed before?

It's the first time I program something :).

Is this right?
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));
summe = summand1 + summand2 ;
}
}
}

  • 0

#12 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 - 12:11 PM

No it's not. Switch:

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

with:

summe = summand1 + summand2;

And start with some ebook. You can't learn how to program in way that people write simple code for you. Find some (anyone) ebook for begining and read it and practice it.
  • 0

Microsoft Student Partner, Microsoft Certified Professional






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