Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Inheritance WinForms Pin
Cynizm15-May-13 7:04
Cynizm15-May-13 7:04 
GeneralRe: Inheritance WinForms Pin
Dave Kreskowiak15-May-13 12:42
mveDave Kreskowiak15-May-13 12:42 
AnswerRe: Inheritance WinForms Pin
Abhinav S15-May-13 7:56
Abhinav S15-May-13 7:56 
QuestionConsuming REST service from C# code Pin
Subin Mavunkal15-May-13 4:21
Subin Mavunkal15-May-13 4:21 
AnswerRe: Consuming REST service from C# code Pin
Abhinav S15-May-13 7:52
Abhinav S15-May-13 7:52 
QuestionWin7 FolderBrowser on ext. Dev doesn't work Pin
boogey4all.beds14-May-13 22:46
boogey4all.beds14-May-13 22:46 
AnswerRe: Win7 FolderBrowser on ext. Dev doesn't work Pin
dusty_dex15-May-13 0:27
dusty_dex15-May-13 0:27 
GeneralMethod Not Returning a Value Pin
N8tiv14-May-13 19:34
N8tiv14-May-13 19:34 
Instead of trying to type this up, which would take forever… I recorded my screen and uploaded it to YouTube.
Here is the link to the video:
[^]

C#
using System;

namespace CalculatetothePowerof
{
    class Program
    {
        static void Main()
        {
            AcceptValueOne();
        }
        static int AcceptValueOne()
        {
            Console.WriteLine("Enter your first number:");
            string valueOne = Console.ReadLine();
            int IntOne = 0;
            bool result = Int32.TryParse(valueOne, out IntOne);
            if (!result)
            {
                Console.WriteLine("Attempted conversion of '{0}' failed.", IntOne);
                AcceptValueOne();
            }
            Console.WriteLine("\n{0}", IntOne + ", is what you entered?\n\nPress lowercase y for yes\nPress lowercase n for no.");
            string yesNo = Console.ReadLine();
            if (yesNo == "y")
            {
                AcceptValueTwo();
            }
            if (yesNo == "n")
            {
                Console.Clear();
                AcceptValueOne();
            }
            else if (yesNo != null)
            {
                Console.Clear();
                AcceptValueOne();
            }
            return IntOne;
        }
        static int AcceptValueTwo()
        {
            Console.WriteLine("\nEnter your second number:");
            string valueTwo = Console.ReadLine();
            int IntTwo = 0;
            bool result = Int32.TryParse(valueTwo, out IntTwo);
            if (!result)
            {
                Console.WriteLine("Attempted conversion of '{0}' failed.", IntTwo);
                AcceptValueTwo();
            }
            Console.WriteLine("\n{0}", IntTwo + ", is what you entered?\n\nPress lowercase y for yes\nPress lowercase n for no.");
            string yesNo = Console.ReadLine();
            if (yesNo == "y")
            {
                CalcPowerOf();
            }
            if (yesNo == "n")
            {
                Console.Clear();
                AcceptValueTwo();
            }
            if (yesNo != null)
            {
                Console.Clear();
                AcceptValueTwo();
            }
            return IntTwo;
        }
        int valOne = AcceptValueOne();
        int valTwo = AcceptValueTwo();
        static void CalcPowerOf()
        {
            Program MyObj = new Program();
            Console.WriteLine(Math.Pow(MyObj.valOne, MyObj.valTwo));
            Console.Read();
        }
   }
}




When I changed this:
C#
int valOne = AcceptValueOne();
int valTwo = AcceptValueTwo();


Into this:
C#
int valOne = IntOne;
int valTwo = IntTwo;


Blue squiggly lines appear underneath both:
IntOne;
IntTwo;

Does not exist in the current context.



If you make any changes to my code, please explain what you're doing and why.

Thank you to all who took the time.

Rob

AnswerRe: Method Not Returning a Value Pin
parths14-May-13 20:05
parths14-May-13 20:05 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan14-May-13 21:24
mveRichard MacCutchan14-May-13 21:24 
GeneralRe: Method Not Returning a Value Pin
N8tiv15-May-13 20:29
N8tiv15-May-13 20:29 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan15-May-13 21:46
mveRichard MacCutchan15-May-13 21:46 
GeneralRe: Method Not Returning a Value Pin
N8tiv15-May-13 23:10
N8tiv15-May-13 23:10 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 1:17
mveRichard MacCutchan16-May-13 1:17 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 4:27
N8tiv16-May-13 4:27 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 5:02
mveRichard MacCutchan16-May-13 5:02 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 6:13
N8tiv16-May-13 6:13 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 6:46
mveRichard MacCutchan16-May-13 6:46 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 7:42
N8tiv16-May-13 7:42 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan16-May-13 20:40
mveRichard MacCutchan16-May-13 20:40 
GeneralRe: Method Not Returning a Value Pin
N8tiv17-May-13 11:31
N8tiv17-May-13 11:31 
GeneralRe: Method Not Returning a Value Pin
Richard MacCutchan17-May-13 22:50
mveRichard MacCutchan17-May-13 22:50 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon14-May-13 23:07
mvePete O'Hanlon14-May-13 23:07 
GeneralRe: Method Not Returning a Value Pin
N8tiv15-May-13 20:37
N8tiv15-May-13 20:37 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon15-May-13 23:50
mvePete O'Hanlon15-May-13 23:50 

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.