dn54321
New member
- Joined
- Dec 29, 2014
- Messages
- 1
- Programming Experience
- Beginner
Soo i ran my code to find out LINE 30 and LINE 42 has an issue. Used of Unassigned local variable 'c' 'd'
if you can help me solve it, it would be great! Be sure to provide me with major feedback about the problems i've done and how i can improve
i'm still very terrible at c# this is my first program so don't throw code at me without an explaination of what it does.
People are actually bothered to read this..
if you can help me solve it, it would be great! Be sure to provide me with major feedback about the problems i've done and how i can improve
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CPractise
{
class Startup
{
static void Main(string[] args)
{
int x = 0;
while (x != -1)
{
Console.WriteLine("What would you like? Type help for all commands!");
string ans = Console.ReadLine();
if (ans == "help")
{
Console.WriteLine("Methods - Displays all methods used in this program");
}
else if (ans == "Methods")
{
Console.WriteLine("Power - Allows program to calculate power...");
}
else if (ans == "Power")
{
int a; int b; string c; string d;
Console.WriteLine("Welcome to Power Method! Type exit to exit \n Please insert the base number:");
while (!(c = "exit")) //line 30
{
c = Console.ReadLine();
if (c == "exit")
{
Console.WriteLine("Exiting...");
System.Threading.Thread.Sleep(1000);
Console.Clear();
}
else if (int.TryParse(c, out a))
{
a = int.Parse(c);
while (!(d == "exit") || int.TryParse(d, out b)) //line 42
{
Console.WriteLine("Now insert power:");
d = Console.ReadLine();
if (d == "exit")
{
Console.WriteLine("Exiting...");
System.Threading.Thread.Sleep(1000);
Console.Clear();
}
else if (int.TryParse(d, out b))
{
b = int.Parse(d);
Power ans1 = new Power();
int answer = ans1.p(a, b);
Console.WriteLine("Base Number = {0} \n Power Number = {1} \n Result of {0}^{1} = {2}", a, b, ans1);
}
else Console.WriteLine("Silly user... {0} is not a number..", d);
}
}
else Console.WriteLine("Silly user... {0} is not a number..", c);
}
}
else
{
Console.WriteLine("Error 101: Command is invalid \n Type help for further information...");
System.Threading.Thread.Sleep(3000);
Console.Clear();
}
}
}
}
}
}
}
Last edited: