Click here to Skip to main content
16,018,353 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting the names of files have extension of mp3 from filesystem?? Pin
Jared Bienz [MSFT]28-Nov-07 12:36
Jared Bienz [MSFT]28-Nov-07 12:36 
GeneralRe: Getting the names of files have extension of mp3 from filesystem?? Pin
Luc Pattyn28-Nov-07 21:50
sitebuilderLuc Pattyn28-Nov-07 21:50 
AnswerRe: Getting the names of files have extension of mp3 from filesystem?? Pin
omegazafer28-Nov-07 12:41
omegazafer28-Nov-07 12:41 
QuestionIdentifier Expected Pin
murtle328-Nov-07 11:31
murtle328-Nov-07 11:31 
AnswerRe: Identifier Expected Pin
Luc Pattyn28-Nov-07 11:38
sitebuilderLuc Pattyn28-Nov-07 11:38 
GeneralRe: Identifier Expected Pin
murtle328-Nov-07 12:00
murtle328-Nov-07 12:00 
GeneralRe: Identifier Expected Pin
Luc Pattyn28-Nov-07 12:21
sitebuilderLuc Pattyn28-Nov-07 12:21 
AnswerRe: Identifier Expected Pin
Jared Bienz [MSFT]28-Nov-07 12:08
Jared Bienz [MSFT]28-Nov-07 12:08 
First off, Welcome to Programming C#! It's my favorite language.

There are a handfull of issues, but at least you gave it the good old college try. Smile | :)

Let's get started: You were missing a close curly brace at the end, though that could have simply not made it to your clipboard.

Next, (and this was the 'Identifier Expected' issue) in DspAvg you didn't define the data type for num1 num2 or num3. You must specify that they're double.

After that, in DspAvg you also can't mark those parameters as 'out' because DspAvg never assigns them a value -- it just prints them on the screen. The 'out' keyword signifies that a value will be assigned to the parameter before the method returns.

The same thing happened in CalcAvg. No need to mark them as 'out' since they're not being assigned in the method.

In CalcAvg you explicitly cast avgNum to a double, which isn't necessary since avgNum is defined as a double at the beginning of the method. It'll still compile, but it's unecessary.

Now, here it get's a little interesting. Smile | :) DspAgv is marked to return a double, but no value is returned (and one shouldn't be because you're just displaying the results). However, your CalcAvg method doesn't return a value and of course it really should.

In Main it looks like you were trying to use DspAvg to show the collected values, but DspAvg requires a fourth parameter (the calculated average). You could either remove that parameter or not use DspAvg until you've done the calculation.

In Main, when you call CalcAvg you'll need to store the return value.

You should probably have a Console.ReadLine at the end or the window will close before you see the results (if debugging in Visual Studio).

Here are the changes, hope it works for you. Now please don't expect another free homework assignment, but DO enjoy learning C#. Laugh | :laugh:

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
<br />
namespace Program10<br />
{<br />
    class Program<br />
    {<br />
        static void GetNums(out double num1, out double num2, out double num3)<br />
        {<br />
            Console.Write("Enter first number: ");<br />
            num1 = double.Parse(Console.ReadLine());<br />
            Console.Write("Enter second number: ");<br />
            num2 = double.Parse(Console.ReadLine());<br />
            Console.Write("Enter third number: ");<br />
            num3 = double.Parse(Console.ReadLine());<br />
        }<br />
<br />
        static double CalcAvg(double num1, double num2, double num3)<br />
        {<br />
            double avgNum;<br />
            avgNum = num1 + num2 + num3;<br />
            avgNum = avgNum / 3;<br />
<br />
            return avgNum;<br />
        }<br />
<br />
        static void DspAvg(double avgNum, double num1, double num2, double num3)<br />
        {<br />
            Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum);<br />
        }<br />
<br />
        static void Main()<br />
        {<br />
            double firstNum, secNum, thirdNum;<br />
            GetNums(out firstNum, out secNum, out thirdNum);<br />
            double avgNum = CalcAvg(firstNum, secNum, thirdNum);<br />
            DspAvg(avgNum, firstNum, secNum, thirdNum);<br />
            Console.WriteLine("Press Enter to end the application.");<br />
            Console.ReadLine();<br />
        }<br />
<br />
    }<br />
}<br />


My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.

GeneralRe: Identifier Expected Pin
murtle328-Nov-07 12:16
murtle328-Nov-07 12:16 
GeneralRe: Identifier Expected Pin
Jared Bienz [MSFT]28-Nov-07 12:19
Jared Bienz [MSFT]28-Nov-07 12:19 
JokeRe: Identifier Expected Pin
Pete O'Hanlon28-Nov-07 22:16
mvePete O'Hanlon28-Nov-07 22:16 
GeneralRe: Identifier Expected Pin
Luc Pattyn28-Nov-07 22:40
sitebuilderLuc Pattyn28-Nov-07 22:40 
GeneralRe: Identifier Expected Pin
Pete O'Hanlon28-Nov-07 23:11
mvePete O'Hanlon28-Nov-07 23:11 
GeneralRe: Identifier Expected Pin
Anthony Mushrow28-Nov-07 12:19
professionalAnthony Mushrow28-Nov-07 12:19 
GeneralRe: Identifier Expected Pin
Jared Bienz [MSFT]28-Nov-07 12:37
Jared Bienz [MSFT]28-Nov-07 12:37 
QuestionNew to Remoting (C#) Pin
mevivekdua28-Nov-07 10:57
mevivekdua28-Nov-07 10:57 
AnswerRe: New to Remoting (C#) Pin
Pete O'Hanlon28-Nov-07 11:08
mvePete O'Hanlon28-Nov-07 11:08 
GeneralRe: New to Remoting (C#) Pin
Jared Bienz [MSFT]28-Nov-07 11:33
Jared Bienz [MSFT]28-Nov-07 11:33 
GeneralRe: New to Remoting (C#) Pin
Pete O'Hanlon28-Nov-07 21:53
mvePete O'Hanlon28-Nov-07 21:53 
AnswerRe: New to Remoting (C#) Pin
Paul Conrad28-Nov-07 12:32
professionalPaul Conrad28-Nov-07 12:32 
QuestiondialogBox performClick itself Pin
gizmokaka28-Nov-07 10:15
gizmokaka28-Nov-07 10:15 
AnswerRe: dialogBox performClick itself Pin
Anthony Mushrow28-Nov-07 10:35
professionalAnthony Mushrow28-Nov-07 10:35 
GeneralRe: dialogBox performClick itself Pin
gizmokaka28-Nov-07 11:02
gizmokaka28-Nov-07 11:02 
QuestionInheritance on ListViewSubItem, BackColor Pin
T.Willey28-Nov-07 8:04
T.Willey28-Nov-07 8:04 
AnswerRe: Inheritance on ListViewSubItem, BackColor Pin
led mike28-Nov-07 10:00
led mike28-Nov-07 10:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.