Ta sig vidare i programmeringen?
Fastat totalt i programmeringen. Är nybörjare helt klart. Har endast gjort en handfull simpla program utan att ha avancerat de minsta..
Och det är det jag vill göra nu. Vill få ut något (suddigt beskrivet) av programmen.
Satt med detta igårnatt :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace conFormula
{
class Program
{
private void keyPressed(object sender, KeyPressEventArgs e)
{
}
int choice = -1;
private void Navigate()
{
while (choice!=0) //skriv 0 = avslutar programmet.
{
try
{
choice = int.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("\nwrong input, please choose between 0-3");
// kör om metoden
}
switch (choice)
{
case 1:
calcPQ();
break;
case 2:
areaCal();
break;
case 3:
calPerimeter();
break;
case 4:
areaCircle();
break;
case 0:
Environment.Exit(0);
break;
}
}
}
// PQ formeln
public static void calcPQ() {
try
{
Console.WriteLine("You have choosen the formula (PQ formula) insert the following please: ");
Console.WriteLine("Type the value of 'p': ");
//input
double p = double.Parse(Console.ReadLine());
Console.WriteLine("Type your value of 'q': ");
//input
double q = double.Parse(Console.ReadLine());
Console.WriteLine("Processing...");
System.Threading.Thread.Sleep(2000);
//Executing the formula
double x1 = -(p / 2) + Math.Sqrt(Math.Pow((p / 2), 2) - q);
double x2 = -(p / 2) - Math.Sqrt(Math.Pow((p / 2), 2) - q);
Console.WriteLine("Result: " + x1, x2);
}
catch (InvalidCastException e)
{
throw (e);
}
}
// omkretsen av en rektangel
public static void calPerimeter()
{
try
{
Console.WriteLine("You have chossen the formula (Perimeter calculation). Insert the following please: ");
Console.WriteLine("Insert width(cm): ");
double width = double.Parse(Console.ReadLine());
Console.WriteLine("Insert height(cm): ");
double height = double.Parse(Console.ReadLine());
double total = width * 2 + height * 2;
Console.WriteLine("Perimeter is = " + total + "cm");
Console.WriteLine("Thank you for using my program. Once again, press either 1,2,3 & 4 to navigate through different formulas.");
}
catch (Exception)
{
Console.WriteLine("An error occured. Try again.");
}
}
// A = π × r2
public static void areaCircle()
{
Console.WriteLine("You have choosen the formula (Area of circle). Insert the following: ");
Console.WriteLine("Insert the radius(cm): ");
double r = double.Parse(Console.ReadLine());
double pi = 3.14;
double total = pi * (r * r);
Console.WriteLine("Area of your circle is: " + total +"cm");
}
//Area av en rektangel
public static void areaCal()
{
try
{
Console.WriteLine("You have choosen the formula (Area of rectangle). Insert the following please :");
Console.WriteLine("Insert width(cm): ");
double width = double.Parse(Console.ReadLine());
Console.WriteLine("Insert height(cm): ");
double height = double.Parse(Console.ReadLine());
double answer = width * height;
Console.WriteLine("Area of your rectangel is : +" + answer + "cm");
}
catch (Exception)
{
Console.WriteLine("An error occured.");
}
}
public static void Start()
{
string welcome = "Welcome to my formula programe. Pick a formula by typing the number. 1.(PQ Formula), 2.(Area of rectangle), 3.(The perimeter of a rectangle), 4.(Area of circle), and 0 to exit.";
Console.WriteLine(welcome);
}
static void Main(string[] args)
{
Start();
Program p = new Program();
p.Navigate();
Program q = new Program();
Console.ReadKey();
}
}
}
Det är något enkelt fomelprogram jag slängt ihop. Men vet inte hur jag ska gå vidare utifrån det här? Om vi bortser ifrån att lägga till fler olika formler att räkna ut, för det kan göras i sömnen.
Tex, programmet är ju i Console fönstret nu. Kanske skulle vara något om jag fick programmet i ett snyggt fönster med knappar och sådant? Jag vet inte, därför vänder jag mig för råd till er!
Vad skulle nästa steg för mig vara?
Tack!