2 Replies - 412 Views - Last Post: 04 October 2012 - 02:04 AM Rate Topic: -----

#1 tanky  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 02-August 12

How Userinput in Console call method and output userinput

Posted 03 October 2012 - 09:30 PM

Hi i am lost on how to get the console to take a menu list and take the user input 1 to 4 and call mehod to output the volume of Cylinder,Cone,spher this what i got so far but lost on how to implement it .

class Program
    {
        
        //read and write to cmd 
        static void Main(string[] args)
        {

       
            Console.WriteLine("Welcome to the Volume Helper");
            Console.WriteLine(" ");
            Console.WriteLine("Please Chose a Option:");
            Console.WriteLine("1.Cylinder");
            Console.WriteLine("2.Cone");
            Console.WriteLine("3.Spher");
            Console.WriteLine("4.Exit");
            Console.ReadLine();
              }
            // getuserinput
        static void getuserinput(string Cylinder, string Cone, string Spher)
        {
           
            Console.ReadKey();
         
              
        }
         static void getuseraction(string volume);
         {
           Console.writeline("the volume is ");
         }

        // Gets the volume of a Cylinder.
  
        static Double Cylinder(Double Radius, Double Height)
        {
            Double pi = 3.14159;
            Double volume = pi * (Radius * Radius) * Height;
            return volume;
        }

        // Gets the volume of a Sphere.   
        static Double Sphere(Double Radius)
        {
            Double fraction = (4 / 3);
            Double pi = 3.14159;
            Double volume = fraction * pi * (Radius * Radius * Radius);
            return volume;
        }

        // Gets the volume of a Cone.
     
        static Double Cone(Double Base, Double Height, Double Radius)
        {
            Double fraction = 1 / 3;
            Double pi = 3.14159;
            Double volume = fraction * pi * (Radius * Radius) * Height;
            return volume;
        }

        }
}



Is This A Good Question/Topic? 0
  • +

Replies To: How Userinput in Console call method and output userinput

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3183
  • View blog
  • Posts: 9,645
  • Joined: 05-May 12

Re: How Userinput in Console call method and output userinput

Posted 03 October 2012 - 10:05 PM

You are already outputting the menu. To get the user's input, collect the return value of Console.ReadLine() that you have on line 16.
http://msdn.microsof...e.readline.aspx

And then the same way you prompted with menu and got the menu choice, you should prompt and read the appropriate inputs for the computation that is needed. e.g. ask for the radius, height, and/or base. Once you have those values, you can pass them to your functions. You have covered function calls in your class, right? Otherwise, why would you have written those functions unless you are cribbing them from somebody else.
Was This Post Helpful? 1
  • +
  • -

#3 tanky  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 26
  • Joined: 02-August 12

Re: How Userinput in Console call method and output userinput

Posted 04 October 2012 - 02:04 AM

View PostSkydiver, on 03 October 2012 - 10:05 PM, said:

You are already outputting the menu. To get the user's input, collect the return value of Console.Read Line() that you have on line 16.
http://msdn.microsof...e.readline.aspx

And then the same way you prompted with menu and got the menu choice, you should prompt and read the appropriate inputs for the computation that is needed. e.g. ask for the radius, height, and/or base. Once you have those values, you can pass them to your functions. You have covered function calls in your class, right? Otherwise, why would you have written those functions unless you are cribbing them from somebody else.

Hi thank you for reply i forgot how to its been about 9 months that i write a console so i basically forgot the steps thank you for the refresher and the link
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1