Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

why this msg?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vinnie - 03 Sep 2007 22:31 GMT
this is my little code, the msg i get is:
a) Error    2    'dico.Program.Calcolo(decimal)': not all code paths return
a value    C:\Documents and Settings\Robert\Desktop\prova VS8\dico\dico
\Program.cs    42    43    dico;

b) Error    1    A local variable named 'valueted' cannot be declared in
this scope because it would give a different meaning to 'valueted',
which is already used in a 'parent or current' scope to denote
something else    C:\Documents and Settings\Robert\Desktop\prova VS8\dico
\dico\Program.cs    24    36    dico;

And this is the code:

namespace dico
{
   public class Program
   {
       public static void Main(string[] args)
       {
           decimal value = 0;
           decimal total = 0;
           Insert(value);
           Mostra(value);
           Calcolo(total);

       }

                   public static decimal Insert(decimal valueted)
                       {
                          Console.Write(" Please insert the umber to
evaluate ");
                          string val = Console.ReadLine();
                          decimal valueted = Convert.ToDecimal(val);
                          Console.WriteLine();
                          while (true)
                          {
                               if (valueted >=2)
                               {
                                   return valueted;
                               }
                           Console.WriteLine(" Attenzione valore
minore di due, riprova...");
                           Console.WriteLine();
                          }
                       }

                   public static void Mostra(decimal valueted)
                   {
                       Console.WriteLine(" Il valore da te inserito
come numero di elemnti e': " +valueted);
                   }

                   public static decimal Calcolo(decimal valueted)
                   {

                       for (int i=10; i<=valueted; i--)
                       {
                           Console.WriteLine(" Insert the first
number to use: ");
                           decimal total;
                           total = valueted - 1;
                           Console.WriteLine(total);
                       }
                   }
   }
}

all i was trying to do was to
a) ask for  a number;
b) subtract 1 each time (100-1=99; 99-1=98;...)
c) show the result.

To say that i'm desperate doens't give my right mood now...
Doug Semler - 03 Sep 2007 22:43 GMT
<snip>

I am debating whether to help you with your homework problems (I thought you
said you were familiar with programming?  This is basic first year
functional programming class.)

The error messages are quite clear.
a) Your function Insert isn't returning a value, but you declared it as
returning a decimal.
b) Your function Insert has declared a local variable and parameter of the
same name.
You need to decide whether you want the valuted parameter to be local to the
function and returned, or if you want it to be passed as a ref parameter to
the function.

Your loop in calcolo is definitely not going to work as expected.
Your function calcolo is going to run into the same problem with not
returning a value.

Based on your requirements, you are calling Insert, Calcolo and Mostra in
the wrong order.

Signature

Doug Semler, MCPD
a.a. #705, BAAWA.  EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Ben Voigt [C++ MVP] - 04 Sep 2007 23:17 GMT
> <snip>
>
[quoted text clipped - 5 lines]
> a) Your function Insert isn't returning a value, but you declared it as
> returning a decimal.

To be fair, this one isn't true.  Insert has only one exit point and it does
return a value.

> b) Your function Insert has declared a local variable and parameter of the
> same name.
[quoted text clipped - 8 lines]
> Based on your requirements, you are calling Insert, Calcolo and Mostra in
> the wrong order.
Jon Skeet [C# MVP] - 04 Sep 2007 23:28 GMT
> > The error messages are quite clear.
> > a) Your function Insert isn't returning a value, but you declared it as
> > returning a decimal.
>
> To be fair, this one isn't true.  Insert has only one exit point and it does
> return a value.

Indeed - Doug just got the wrong method. As per the compiler error
message, it's the Calcolo method which doesn't return a value.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Doug Semler - 05 Sep 2007 03:55 GMT
>> <snip>
>>
[quoted text clipped - 8 lines]
> To be fair, this one isn't true.  Insert has only one exit point and it
> does return a value.

Ach, Gott.  I wasn't paying attention and didn't read the error message.
The functionality was so convoluted....

Signature

Doug Semler, MCPD
a.a. #705, BAAWA.  EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

Jon Skeet [C# MVP] - 03 Sep 2007 22:50 GMT
> this is my little code, the msg i get is:
> a) Error    2    'dico.Program.Calcolo(decimal)': not all code paths return
> a value    C:\Documents and Settings\Robert\Desktop\prova VS8\dico\dico
> \Program.cs    42    43    dico;

And it's absolutely right. You've declared that your method will return
a result, but you're not returning anything.

> b) Error    1    A local variable named 'valueted' cannot be declared in
> this scope because it would give a different meaning to 'valueted',
> which is already used in a 'parent or current' scope to denote
> something else    C:\Documents and Settings\Robert\Desktop\prova VS8\dico
> \dico\Program.cs    24    36    dico;

You've got a parameter called valueted, but you're trying to declare a
local variable with the same name. You can't do that.

While we're at it, look at this loop:

for (int i=10; i<=valueted; i--)

Assuming valueted starts off as 12, that's going to last a very long
time:

i=10 - is i <= 12? Yes. i--...
i=9 - is i <= 12? Yes. i--...
i=8 - is i <= 12? Yes. i--...

etc

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.