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

C#

 
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 
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 
Okay, here is what my code looks like now.
I got rid of the third method and moved all of that up into my main method like you suggested.
I put a breakpoint on my main method so I could watch and see what happens.

The compiler didn't complain, as I was able to step through…

Once I hit the integer variable valOne = AcceptValueOne();

It loops back down to my method AcceptValueOne(); and starts all over again.

Yes, I do have a fundamental misunderstanding that I am trying to learn.
I haven't quite figured it out yet.

I know my code is ugly, you old pros are probably wincing and saying something like "Ah, newbie! Your code stinks and you need to change your shorts!"…
Poke tongue | ;-P Laugh | :laugh:

Trying to learn this stuff on my own without any formal classes. Just some e-books and YouTube videos and forums similar to this one.

I know there's probably some shortcut techniques that could be using, like… Maybe a few string arrays and reusing what's in my first method… For right now, let's just leave my code the way it is as much as possible… Because, I wrote it… I understand it… It's what I've learned so far… I'm not just some script kiddie trying to get an easy way out.
I'm doing my best to learn this stuff and understand how and what things do…

You're going to be seeing a lot of me, when I learned something and understand it and how to write it… You'll see it reflected in my code.
For now, these basic things in this post… Is what I know and some of it I'm trying to understand yet.

If you make any changes to my code, please try not to change too much of it… That way I can study what you changed and try to learn from it…

Thank you for replying and trying to help… I appreciate it.

Here is what my code looks like now:

C#
using System;

namespace CalculatetothePowerof
{
    class Program
    {
        static void Main()
        {
            AcceptValueOne();
            AcceptValueTwo();
            int valOne = IntOne;
            int valTwo = IntTwo;
            Console.WriteLine(Math.Pow(valOne, valTwo));
            Console.Read();
        }
        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")
            {
                return IntOne;
            }
            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")
            {
                return IntTwo;
            }
            if (yesNo == "n")
            {
                Console.Clear();
                AcceptValueTwo();
            }
            if (yesNo != null)
            {
                Console.Clear();
                AcceptValueTwo();
            }
            return IntTwo;
        }
   }
}


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 
GeneralRe: Method Not Returning a Value Pin
N8tiv16-May-13 0:29
N8tiv16-May-13 0:29 
GeneralRe: Method Not Returning a Value Pin
Pete O'Hanlon16-May-13 0:36
mvePete O'Hanlon16-May-13 0:36 
QuestionCreating Images on Different Layers Pin
ASPnoob14-May-13 11:40
ASPnoob14-May-13 11:40 

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.