Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Identifier Expected

Identifier Expected

Scheduled Pinned Locked Moved C#
help
12 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    murtle3
    wrote on last edited by
    #1

    Hello, I am trying to create a program that reads in 3 numbers and averages them for my Programming 1 class. I am trying to use method call statements in order to do this. I got it all finished but when I built it I got three "Identifier Expected" errors on line 26, and I don't understand what that means. (I'm rather new) Here is what I've got for coding...I'm not sure if there is anything else I need to change about it other than the 3 errors, either. using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static void CalcAvg(out double num1, out double num2, out double num3) { double avgNum; avgNum = num1 + num2 + num3; avgNum = avgNum / 3; return (double) avgNum; } static double DspAvg(double avgNum, out num1, out num2, out num3) { Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum); } static void Main() { double firstNum, secNum, thirdNum, avgNum; DspAvg(firstNum, secNum, thirdNum); GetNums(out firstNum, out secNum, out thirdNum); CalcAvg(avgNum); } } Thanks in advance for your help! [Ross Murtle] [Computer Science Major - Iowa Central Community College/Iowa State University]

    L J 2 Replies Last reply
    0
    • M murtle3

      Hello, I am trying to create a program that reads in 3 numbers and averages them for my Programming 1 class. I am trying to use method call statements in order to do this. I got it all finished but when I built it I got three "Identifier Expected" errors on line 26, and I don't understand what that means. (I'm rather new) Here is what I've got for coding...I'm not sure if there is anything else I need to change about it other than the 3 errors, either. using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static void CalcAvg(out double num1, out double num2, out double num3) { double avgNum; avgNum = num1 + num2 + num3; avgNum = avgNum / 3; return (double) avgNum; } static double DspAvg(double avgNum, out num1, out num2, out num3) { Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum); } static void Main() { double firstNum, secNum, thirdNum, avgNum; DspAvg(firstNum, secNum, thirdNum); GetNums(out firstNum, out secNum, out thirdNum); CalcAvg(avgNum); } } Thanks in advance for your help! [Ross Murtle] [Computer Science Major - Iowa Central Community College/Iowa State University]

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      and which of these is line 26? don't tell us you are running Visual Studio with line numbering disabled! and please use < PRE > tags for code snippets. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


      M 1 Reply Last reply
      0
      • L Luc Pattyn

        and which of these is line 26? don't tell us you are running Visual Studio with line numbering disabled! and please use < PRE > tags for code snippets. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


        M Offline
        M Offline
        murtle3
        wrote on last edited by
        #3

        static double DspAvg(double avgNum, out num1, out num2, out num3)

        is line 26. Sorry for the confusion. :-D

        L 1 Reply Last reply
        0
        • M murtle3

          Hello, I am trying to create a program that reads in 3 numbers and averages them for my Programming 1 class. I am trying to use method call statements in order to do this. I got it all finished but when I built it I got three "Identifier Expected" errors on line 26, and I don't understand what that means. (I'm rather new) Here is what I've got for coding...I'm not sure if there is anything else I need to change about it other than the 3 errors, either. using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static void CalcAvg(out double num1, out double num2, out double num3) { double avgNum; avgNum = num1 + num2 + num3; avgNum = avgNum / 3; return (double) avgNum; } static double DspAvg(double avgNum, out num1, out num2, out num3) { Console.WriteLine("The average of {0:n}, {1:n}, and {2:n} is {3}", num1, num2, num3, avgNum); } static void Main() { double firstNum, secNum, thirdNum, avgNum; DspAvg(firstNum, secNum, thirdNum); GetNums(out firstNum, out secNum, out thirdNum); CalcAvg(avgNum); } } Thanks in advance for your help! [Ross Murtle] [Computer Science Major - Iowa Central Community College/Iowa State University]

          J Offline
          J Offline
          Jared Bienz MSFT
          wrote on last edited by
          #4

          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. :) 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. :) 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: using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static double CalcAvg(double num1, double num2, double num3) { double avgNum; avgNum = num1 + n

          M A 2 Replies Last reply
          0
          • J Jared Bienz MSFT

            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. :) 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. :) 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: using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static double CalcAvg(double num1, double num2, double num3) { double avgNum; avgNum = num1 + n

            M Offline
            M Offline
            murtle3
            wrote on last edited by
            #5

            Thank you SO MUCH for your help. I have learned from my mistakes and the fact that you took time out of your day to help a measly little college freshman like myself is greatly appreciated! Thanks again! :-D

            J 1 Reply Last reply
            0
            • M murtle3

              Thank you SO MUCH for your help. I have learned from my mistakes and the fact that you took time out of your day to help a measly little college freshman like myself is greatly appreciated! Thanks again! :-D

              J Offline
              J Offline
              Jared Bienz MSFT
              wrote on last edited by
              #6

              No problem at all. The secret to becoming a successful developer is being resourceful and not giving up. Glad I could help.

              My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
              Sites of Interest: MSDN Events | US ISV Team Blog

              P 1 Reply Last reply
              0
              • J Jared Bienz MSFT

                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. :) 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. :) 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: using System; using System.Collections.Generic; using System.Text; namespace Program10 { class Program { static void GetNums(out double num1, out double num2, out double num3) { Console.Write("Enter first number: "); num1 = double.Parse(Console.ReadLine()); Console.Write("Enter second number: "); num2 = double.Parse(Console.ReadLine()); Console.Write("Enter third number: "); num3 = double.Parse(Console.ReadLine()); } static double CalcAvg(double num1, double num2, double num3) { double avgNum; avgNum = num1 + n

                A Offline
                A Offline
                Anthony Mushrow
                wrote on last edited by
                #7

                Jared Bienz [MSFT] wrote:

                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).

                I actually find that: Console.ReadKey(true); Is much better, as soon as you press any key (apart from a select few, NumLock, for example) it will close. The 'true' part means that it will not send the input to the buffer, so you won't actualy see the letter or number you pressed on the screen.

                My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

                J 1 Reply Last reply
                0
                • M murtle3

                  static double DspAvg(double avgNum, out num1, out num2, out num3)

                  is line 26. Sorry for the confusion. :-D

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  num1/2/3 are missing their types, something like int :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                  1 Reply Last reply
                  0
                  • A Anthony Mushrow

                    Jared Bienz [MSFT] wrote:

                    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).

                    I actually find that: Console.ReadKey(true); Is much better, as soon as you press any key (apart from a select few, NumLock, for example) it will close. The 'true' part means that it will not send the input to the buffer, so you won't actualy see the letter or number you pressed on the screen.

                    My current favourite word is: PIE! I have changed my name to my regular internet alias. But don't let the 'Genius' part fool you, you don't know what 'SK' stands for. -The Undefeated

                    J Offline
                    J Offline
                    Jared Bienz MSFT
                    wrote on last edited by
                    #9

                    Ah, much better. Thanks for pointing that out. I'm going to use that from now on in my SequentialWorkflow console demos!

                    My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
                    Sites of Interest: MSDN Events | US ISV Team Blog

                    1 Reply Last reply
                    0
                    • J Jared Bienz MSFT

                      No problem at all. The secret to becoming a successful developer is being resourceful and not giving up. Glad I could help.

                      My posts may include factual data, educated guesses, personal opinion and dry humor. They should not be treated as an official Microsoft statement.
                      Sites of Interest: MSDN Events | US ISV Team Blog

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      Jared Bienz [MSFT] wrote:

                      The secret to becoming a successful developer is being resourceful and not giving up

                      Its not. The secret is caffeine and pizza. Plenty of it.

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      L 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        Jared Bienz [MSFT] wrote:

                        The secret to becoming a successful developer is being resourceful and not giving up

                        Its not. The secret is caffeine and pizza. Plenty of it.

                        Deja View - the feeling that you've seen this post before.

                        My blog | My articles

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        Caffeine and Pizza inherit from Resource, don't they? ;)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                        P 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          Caffeine and Pizza inherit from Resource, don't they? ;)

                          Luc Pattyn [Forum Guidelines] [My Articles]


                          this months tips: - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use PRE tags to preserve formatting when showing multi-line code snippets


                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #12

                          Luc Pattyn wrote:

                          Caffeine and Pizza inherit from Resource, don't they?

                          They do. And best of all, they are Disposable - although the Garbage Collection is a bit unpredictable.;)

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups