473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple math program.

Would someone be kind and explain why and how this works. It comes up with the correct answer, but I dont understand how it does. Wouldn't Console.WriteLine("5+4={0}",5+4); wouldn't it come up as 5+4=1 instead of 5+4=9? Sorry guys im new to all of this but im learning. Thanks for the help in advance!
using System;

namespace SimpleMath

{

class DoMath

{

static void Main(string[] args)

{

int a = 1;
//addition with integers works as expected
Console.WriteLine("5 + 4 = {0}", 5 + 4);
Console.Write("Please press \"enter\" to continue");

Console.ReadLine();

} // end main

} // end class

} // end namespace
--
(\(\
(=':')
(,(")(") Eric Anderson
Dec 5 '05 #1
3 1413
Eric Anderson wrote:
Would someone be kind and explain why and how this works. It comes up with the
correct answer, but I dont understand how it does. Wouldn't
Console.WriteLine("5+4={0}",5+4); wouldn't it come up as 5+4=1 instead of 5+4=9?
Sorry guys im new to all of this but im learning. Thanks for the help in advance!


Why would it come up as 5+4=1?
If you wrote: Console.WriteLine ("5+4={0}", a); that would come up as
5+4=1, but you're passing it the right answer, so I don't see why you'd
expect it to print the wrong one...

Jon

Dec 5 '05 #2
The {0} is substituted for the appropriate argument (in this case 5+4).
The argument evaluates to 9 and is inserted into the string as position
{0}. Why did you expect it to be 1? Not having a go, just interested.

Simon

As a further example

Console.WriteLine("5 + 4 = {0} and 5 - 4 = {1}", 5+4, 5-4);

would result in

5 + 4 = 9 and 5 - 4 = 1

Eric Anderson wrote:
Would someone be kind and explain why and how this works. It comes up
with the correct answer, but I dont understand how it does. Wouldn't
Console.WriteLine("5+4={0}",5+4); wouldn't it come up as 5+4=1 instead
of 5+4=9? Sorry guys im new to all of this but im learning. Thanks for
the help in advance!

using System;

namespace SimpleMath

{

class DoMath

{

static void Main(string[] args)

{

int a = 1;

//addition with integers works as expected

Console.WriteLine("5 + 4 = {0}", 5 + 4);

Console.Write("Please press \"enter\" to continue");

Console.ReadLine();

} // end main

} // end class

} // end namespace
--
(\(\
(=':')
(,(")(") Eric Anderson

Dec 5 '05 #3
Lol I know that 5+4 equals to. The reason why I asked is just to understand what was going on in that line of code, because the book that I am reading didn't clarify what all that meant. And I just want to get a full understanding of everything before I move on to the next part. But thanks guys for clearing that up for me.

--
(\(\
(=':')
(,(")(") Eric Anderson
"Eric Anderson" <ti*********@email.uophx.edu> wrote in message news:eF****************@tk2msftngp13.phx.gbl...
Would someone be kind and explain why and how this works. It comes up with the correct answer, but I dont understand how it does. Wouldn't Console.WriteLine("5+4={0}",5+4); wouldn't it come up as 5+4=1 instead of 5+4=9? Sorry guys im new to all of this but im learning. Thanks for the help in advance!
using System;

namespace SimpleMath

{

class DoMath

{

static void Main(string[] args)

{

int a = 1;
//addition with integers works as expected
Console.WriteLine("5 + 4 = {0}", 5 + 4);
Console.Write("Please press \"enter\" to continue");

Console.ReadLine();

} // end main

} // end class

} // end namespace
--
(\(\
(=':')
(,(")(") Eric Anderson
Dec 5 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: drs | last post by:
Hi, I am trying to find all lists of length x with elements a, b, and c. To this end, I have created the class below, but it is not quite working and I am having trouble figuring out what to...
0
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** ...
1
by: limelight | last post by:
I have discovered a math error in the .NET framework's Log function. It returns incorrect results for varying powers of 2 that depend on whether the program is run from within the IDE or from the...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
7
by: Wernfried Schwenkner | last post by:
I've found the discussion about Math.Log and the error with Math.Log(8,2) on Google. Unfortunatly the full thread isn't on my news server, so I can't reply. The problem doesn't only depend...
10
by: Ron | last post by:
I want to calculate the surface area of a sphere from an inputed radius with option strict on. I guess I am not converting something correctly. Here is what I am doing: I have a textbox...
5
by: aguirre.adolfo | last post by:
Hi, I am a very newbie who would very much appreciate some hints. Python 2.52. on Windows XP for now. Soon on Ubuntu 8 I am teaching myself Python following free tutorials. I can solve...
7
by: bvdp | last post by:
I'm finding my quest for a safe eval() quite frustrating :) Any comments on this: Just forget about getting python to do this and, instead, grab my set of values (from a user supplied text file)...
1
by: astrogirl77 | last post by:
I'm new to C++ and am hoping to find help with coding a simple C program, am wanting to obtain code and functioning exe's. I code in an old version of Visual Basic 4.0, I have a simple app that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.