473,325 Members | 2,805 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,325 software developers and data experts.

so long? no other way?

I'm a self learner, and i'm trying to figure out how this code should
work. What is not clear to me, is why the function InsertNumber is
called 3 times: wasn;t easier to call it just once and put all
together?

There is a call to that function at line 8, 13, 17

1 namespace riprova
2 {
3 public class Program
4 {
5 public static void Main(string[] args)
6 {
7 decimal number = 0;
8 InsertNumber(ref number);
9 Console.Write(" Number to
be considerd: " + number);
10 Console.Read();
11 Show(number);
12 }
13 public static void
InsertNumber(ref decimal number)
14 {
15 number = InsertNumber("
Value ");
16 }
17 public static decimal
InsertNumber(string answer)
18 {
19 Console.WriteLine(" Insert
the value of " + answer);
20 string accept =
Console.ReadLine();
21 decimal value =
Convert.ToDecimal(accept);
22 return value;
23 }
24 public static void
Show(decimal number)
25 {
26 for (int amount = 0;
amount >= number; amount++)
27 {
28 number = (number + 1);
29
Console.WriteLine(number);
30 Console.ReadLine();
31 Console.Read();
32 }
33 }
34 }
35 }

Sep 4 '07 #1
11 1149
Vinnie,

InsertNumber appears to be called two times, and it's not the same
version of InsertNumber that is called. Basically, the overload of
InsertNumber which takes a string seems to be querying the user for the
number, and then doing the conversion. The overload that returns a decimal
doesn't really do much.

I think the program would make more sense if the overload of
InsertNumber which took a string was called something else. This way, you
wouldn't be confused about the naming.

Overall, the code could be broken out better, IMO.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"vinnie" <ce**********@gmail.comwrote in message
news:11**********************@19g2000hsx.googlegro ups.com...
I'm a self learner, and i'm trying to figure out how this code should
work. What is not clear to me, is why the function InsertNumber is
called 3 times: wasn;t easier to call it just once and put all
together?

There is a call to that function at line 8, 13, 17

1 namespace riprova
2 {
3 public class Program
4 {
5 public static void Main(string[] args)
6 {
7 decimal number = 0;
8 InsertNumber(ref number);
9 Console.Write(" Number to
be considerd: " + number);
10 Console.Read();
11 Show(number);
12 }
13 public static void
InsertNumber(ref decimal number)
14 {
15 number = InsertNumber("
Value ");
16 }
17 public static decimal
InsertNumber(string answer)
18 {
19 Console.WriteLine(" Insert
the value of " + answer);
20 string accept =
Console.ReadLine();
21 decimal value =
Convert.ToDecimal(accept);
22 return value;
23 }
24 public static void
Show(decimal number)
25 {
26 for (int amount = 0;
amount >= number; amount++)
27 {
28 number = (number + 1);
29
Console.WriteLine(number);
30 Console.ReadLine();
31 Console.Read();
32 }
33 }
34 }
35 }

Sep 4 '07 #2
On Sep 4, 11:02 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Vinnie,

InsertNumber appears to be called two times, and it's not the same
version of InsertNumber that is called. Basically, the overload of
InsertNumber which takes a string seems to be querying the user for the
number, and then doing the conversion. The overload that returns a decimal
doesn't really do much.

I think the program would make more sense if the overload of
InsertNumber which took a string was called something else. This way, you
wouldn't be confused about the naming.

Overall, the code could be broken out better, IMO.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

Hi Nicholais, thanks for that.

Can you help me to make it more "understandable" ? I'm really so
confused

Thanks

Sep 4 '07 #3
vinnie,

Which part of the code are you confused about?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"vinnie" <ce**********@gmail.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
On Sep 4, 11:02 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Vinnie,

InsertNumber appears to be called two times, and it's not the same
version of InsertNumber that is called. Basically, the overload of
InsertNumber which takes a string seems to be querying the user for the
number, and then doing the conversion. The overload that returns a
decimal
doesn't really do much.

I think the program would make more sense if the overload of
InsertNumber which took a string was called something else. This way,
you
wouldn't be confused about the naming.

Overall, the code could be broken out better, IMO.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com


Hi Nicholais, thanks for that.

Can you help me to make it more "understandable" ? I'm really so
confused

Thanks

Sep 4 '07 #4
On Sep 4, 11:56 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
vinnie,

Which part of the code are you confused about?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"vinnie" <centro.ga...@gmail.comwrote in message

news:11*********************@o80g2000hse.googlegro ups.com...
On Sep 4, 11:02 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
Vinnie,
InsertNumber appears to be called two times, and it's not the same
version of InsertNumber that is called. Basically, the overload of
InsertNumber which takes a string seems to be querying the user for the
number, and then doing the conversion. The overload that returns a
decimal
doesn't really do much.
I think the program would make more sense if the overload of
InsertNumber which took a string was called something else. This way,
you
wouldn't be confused about the naming.
Overall, the code could be broken out better, IMO.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Hi NIcholais,
i read you answer and i agree that is really hard to follow,
especially for me that i'm starting now.

What i don't really understand, is why i have to use 3 times a
function that has the same name: i just copied from the book, so i
don't really know how to change it.

I'm making my step toward the C# and it's harder than i though.

However, why i can't just make it this way:
a) ask the number;
b) verify the number;
c) do the operation (subtraction);
d) show the result.

Why i need to build a so difficult code?

Sep 4 '07 #5
You still seem to be confused with the Console.Read and Console.ReadLine
methods. I suggest you take these out except for the one in
InsertNumber(string), as that one is necessary. Run in the debugger and
break in Show() at the console.writeline. You appear to be increasing your
loop limit each iteration through the loop.

"vinnie" wrote:
I'm a self learner, and i'm trying to figure out how this code should
work. What is not clear to me, is why the function InsertNumber is
called 3 times: wasn;t easier to call it just once and put all
together?

There is a call to that function at line 8, 13, 17

1 namespace riprova
2 {
3 public class Program
4 {
5 public static void Main(string[] args)
6 {
7 decimal number = 0;
8 InsertNumber(ref number);
9 Console.Write(" Number to
be considerd: " + number);
10 Console.Read();
11 Show(number);
12 }
13 public static void
InsertNumber(ref decimal number)
14 {
15 number = InsertNumber("
Value ");
16 }
17 public static decimal
InsertNumber(string answer)
18 {
19 Console.WriteLine(" Insert
the value of " + answer);
20 string accept =
Console.ReadLine();
21 decimal value =
Convert.ToDecimal(accept);
22 return value;
23 }
24 public static void
Show(decimal number)
25 {
26 for (int amount = 0;
amount >= number; amount++)
27 {
28 number = (number + 1);
29
Console.WriteLine(number);
30 Console.ReadLine();
31 Console.Read();
32 }
33 }
34 }
35 }

Sep 4 '07 #6
Vinnie,

I don't see any subtraction anywhere in your code...
"vinnie" wrote:
On Sep 4, 11:56 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
vinnie,

Which part of the code are you confused about?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"vinnie" <centro.ga...@gmail.comwrote in message

news:11*********************@o80g2000hse.googlegro ups.com...
On Sep 4, 11:02 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Vinnie,
> InsertNumber appears to be called two times, and it's not the same
>version of InsertNumber that is called. Basically, the overload of
>InsertNumber which takes a string seems to be querying the user for the
>number, and then doing the conversion. The overload that returns a
>decimal
>doesn't really do much.
> I think the program would make more sense if the overload of
>InsertNumber which took a string was called something else. This way,
>you
>wouldn't be confused about the naming.
> Overall, the code could be broken out better, IMO.
>--
> - Nicholas Paldino [.NET/C# MVP]
> - m...@spam.guard.caspershouse.com

Hi NIcholais,
i read you answer and i agree that is really hard to follow,
especially for me that i'm starting now.

What i don't really understand, is why i have to use 3 times a
function that has the same name: i just copied from the book, so i
don't really know how to change it.

I'm making my step toward the C# and it's harder than i though.

However, why i can't just make it this way:
a) ask the number;
b) verify the number;
c) do the operation (subtraction);
d) show the result.

Why i need to build a so difficult code?

Sep 4 '07 #7
On Sep 4, 11:56 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
vinnie,

Which part of the code are you confused about?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
Hey i saw your web site: really nice!

Btw, are you ready to challenge our paintball team? :)

I was reading you Bio, like mine... but i'm just in the southern part
of US

I agree with you: you can;t be successful if you don;t love what you
do...

Sep 4 '07 #8
It appears to me that the code sample provided is not trying to be the *most
efficient* code possible, but instead it's making an attempt to show you
(the reader) some of the features of the language/framework. Such as
passing a value "by reference", method overloading, method return values,
converting/parsing, looping, etc.

The part that I think you are having a problem understanding is "method
overloading" and the way the author uses it.

HTH,
Mythran
Sep 4 '07 #9

"Mythran" <ki********@hotmail.comwrote in message
news:85**********************************@microsof t.com...
It appears to me that the code sample provided is not trying to be the
*most efficient* code possible, but instead it's making an attempt to show
you (the reader) some of the features of the language/framework. Such as
passing a value "by reference", method overloading, method return values,
converting/parsing, looping, etc.

The part that I think you are having a problem understanding is "method
overloading" and the way the author uses it.
Probably because it is a wholly inappropriate use of overloading.

There are several well-known good uses for overloading:
(1) provide default arguments
(2) treat certain types specially for increased efficiency while still
performing the same conceptual task
(3) ??? I'm sure someone else knows another good use but I can't think of
one right now.
>
HTH,
Mythran


Sep 4 '07 #10
On Sep 4, 6:42 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
"Mythran" <kip_pot...@hotmail.comwrote in message

news:85**********************************@microsof t.com...
It appears to me that the code sample provided is not trying to be the
*most efficient* code possible, but instead it's making an attempt to show
you (the reader) some of the features of the language/framework. Such as
passing a value "by reference", method overloading, method return values,
converting/parsing, looping, etc.
The part that I think you are having a problem understanding is "method
overloading" and the way the author uses it.

Probably because it is a wholly inappropriate use of overloading.

There are several well-known good uses for overloading:
(1) provide default arguments
(2) treat certain types specially for increased efficiency while still
performing the same conceptual task
(3) ??? I'm sure someone else knows another good use but I can't think of
one right now.
Adding to or changing the behavior of a public interface while not
touching the behavior of previously released interfaces.

True story:
We have a product released with an interface function that accepts a
idle timeout value as an integer. One problem: the units of the
timeout are specified in hours. That means that the minimum idle
timeout is 1 HOUR. This function is COM visible. We had a request to
be able to pass in a more fine grained time span for the idle timeout.

Solution: Add a function overload. All current applications behave in
the same manner. Reqesting developer only has to modify one line of
code to pass a timespan instead of an integer. Everybody's happy <g>

Sep 5 '07 #11

"Doug Semler" <do********@gmail.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
On Sep 4, 6:42 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
>"Mythran" <kip_pot...@hotmail.comwrote in message

news:85**********************************@microso ft.com...
It appears to me that the code sample provided is not trying to be the
*most efficient* code possible, but instead it's making an attempt to
show
you (the reader) some of the features of the language/framework. Such
as
passing a value "by reference", method overloading, method return
values,
converting/parsing, looping, etc.
The part that I think you are having a problem understanding is "method
overloading" and the way the author uses it.

Probably because it is a wholly inappropriate use of overloading.

There are several well-known good uses for overloading:
(1) provide default arguments
(2) treat certain types specially for increased efficiency while still
performing the same conceptual task
(3) ??? I'm sure someone else knows another good use but I can't think of
one right now.

Adding to or changing the behavior of a public interface while not
touching the behavior of previously released interfaces.

True story:
We have a product released with an interface function that accepts a
idle timeout value as an integer. One problem: the units of the
timeout are specified in hours. That means that the minimum idle
timeout is 1 HOUR. This function is COM visible. We had a request to
be able to pass in a more fine grained time span for the idle timeout.

Solution: Add a function overload. All current applications behave in
the same manner. Reqesting developer only has to modify one line of
code to pass a timespan instead of an integer. Everybody's happy <g>
I think that's a case of #2 or very close. If it wasn't, then it would be
better to use a new name and not overload the existing one.

One problem with your change is that although existing programs keep working
fine, you may change the meaning of other people's source code. Probably
not in your specific case, but it's a potential problem in general.
Sep 5 '07 #12

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

Similar topics

8
by: Tim Clacy | last post by:
How is a 64 bit type defined in strict C++? It seems C has support for 'long long' since C99, but not so for C++? Looking through one compiler vendor's standard library headers has clouded the...
7
by: William Payne | last post by:
Hello, I have a variable of type unsigned long. It has a number of bits set (with set I mean they equal one). I need to determine those bits and their position and create new numbers from them. For...
5
by: Mark Shelor | last post by:
Problem: find a portable way to determine whether a compiler supports the "long long" type of C99. I thought I had this one solved with the following code: #include <limits.h> #ifdef...
29
by: Richard A. Huebner | last post by:
Is the unsigned long long primitive data type supported in ANSI standard C? I've tried using it a couple of times in standard C, but to no avail. I'm using both MS VIsual C++ 6, as well as the...
9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
21
by: Charles Sullivan | last post by:
I maintain/enhance some inherited FOSS software in C which has compiler options for quite a few different Unix-like operating systems, many of which I've never even heard of. It would be...
12
by: Ahmad Jalil Qarshi | last post by:
Hi, I have an integer value which is very long like 9987967441778573855. Now I want to convert it into equivalent Hex value. The result must be 8A9C63784361021F I have used...
2
by: PengYu.UT | last post by:
Hi, In python, triple quote (""") can be used to quote a paragraph (multiple lines). I'm wondering if there is any equivalent in C++. For the following code, I could write the long string in a...
10
by: ratcharit | last post by:
Currently using cosine function in math.h Currently I get: 1 = cos(1e^-7) Is there another way for cos to return value of high accuracy say: 0.999999 = cos(1e^-7)
15
by: Oliver Graeser | last post by:
I need a >49 bit integer type. tried sizeof(long long), says 8. 8 byte = 64 bit right? but when I try to assign a value with more than 32 bit, it fails. To illustrate: for (i=0; i<64; i++){...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.