Page 1 of 1

Application in C# that can be very useful (my first ever)

Posted: Thu Dec 31, 2009 11:16 am
by EdEown
Ok so here is little discription of this application.
It is my first one ever created.

Function:
It is able to calculate four surface areas of four diffrent object (cube, cylinder, sphere, rectangular)
Time needed: 45 minutes
Future upgrade: I plan to put volumen too. :P
For some it can be bad code, but this is first time I ever wrote anything so if you have some suggestion how to improve it pleas post comments, I would like to learn.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace First_useful_application_done_by_EdE
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, r, h, b, c;
            string pageA;
            string pageB;
            string pageC;
            string radius;
            string hight;
            string objectt;
            Console.WriteLine(@"Please enter for which object do you want to calculate surface area
            (Cube, Rectangular, Sphere or Cylinder)");
            objectt = Console.ReadLine();
            
          
             switch (objectt)
            {
               case "Cube":
                    Console.WriteLine("Give me page A");
                    pageA = Console.ReadLine();
                    Console.WriteLine("The surface area of your cube is: ");
                    a = int.Parse(pageA);
                    Console.WriteLine(6 * ( a * a ) );
                    Console.ReadLine();
                break;
                
                case "Sphere":
                     Console.WriteLine("Give me radius r:");
                     radius = Console.ReadLine();
                     r = int.Parse(radius);
                     Console.WriteLine(4 * 3.14 * (r * r));
                     Console.ReadLine();
                 break;
                
                 case "Cylinder":
                     Console.WriteLine("Give me radius r");
                     radius = Console.ReadLine();
                     r = int.Parse(radius);
                     Console.WriteLine("Give me hight h");
                     hight = Console.ReadLine();
                     h = int.Parse(hight);
                     Console.WriteLine((2 * 3.14 * (r * r)) + (2 * 3.14 * (r * h)));
                     Console.ReadLine();
                 break;
                
                 case "Rectangular":
                     Console.WriteLine("Give me page A");
                     pageA = Console.ReadLine();
                     a = int.Parse(pageA);
                     Console.WriteLine("Give me page B");
                     pageB = Console.ReadLine();
                     b = int.Parse(pageB);
                     Console.WriteLine("Give me page C");
                     pageC = Console.ReadLine();
                     c = int.Parse(pageC);
                 break;


            }   

        }
    }
}
    



I also didnt have any time to check it of fix anything if it is wrong. Sorry

Re: Application in C# that can be very useful (my first ever)

Posted: Fri Jan 01, 2010 2:01 pm
by Lord Pingas
Well done on your first program :)

Re: Application in C# that can be very useful (my first ever)

Posted: Fri Jan 01, 2010 2:33 pm
by avansc
not bad. but you might wanna make separate functions for easy calculation.

Re: Application in C# that can be very useful (my first ever)

Posted: Fri Jan 01, 2010 2:58 pm
by GroundUpEngine
Looks great 8-)

Re: Application in C# that can be very useful (my first ever)

Posted: Fri Jan 01, 2010 3:05 pm
by EdEown
avansc wrote:not bad. but you might wanna make separate functions for easy calculation.
Thanks. I thought some one will start to laugh on it..xD :worship:

Re: Application in C# that can be very useful (my first ever)

Posted: Fri Jan 01, 2010 4:43 pm
by Bakkon
Just a few nit-picks. I see you're from Bosnia, so this might just be a language issue, but what we're calling "page" is typically referred to as a "face". Also, "hight" should be spelled "height". I agree with breaking it down into functions. You have a lot of reused lines to get information from the user. Maybe do something like:

Code: Select all

public int getNumber(string question)
so you can call it like this:

Code: Select all

height = getNumber("Give me height h:");
Also maybe define PI in case you ever need to adjust significant digits and you don't have 3.14 floating around as well as helper functions for calculating each geometry type.

Re: Application in C# that can be very useful (my first ever)

Posted: Sat Jan 02, 2010 3:23 am
by EdEown
Bakkon wrote:Just a few nit-picks. I see you're from Bosnia, so this might just be a language issue, but what we're calling "page" is typically referred to as a "face". Also, "hight" should be spelled "height". I agree with breaking it down into functions. You have a lot of reused lines to get information from the user. Maybe do something like:

Code: Select all

public int getNumber(string question)
so you can call it like this:

Code: Select all

height = getNumber("Give me height h:");
Also maybe define PI in case you ever need to adjust significant digits and you don't have 3.14 floating around as well as helper functions for calculating each geometry type.
Thanks for understanding :P
I have started to learn programing about 6 days ago and dont understand many things, this program is just based on my knowlage.
I trayed to apply your code but I dont know who to really do it (where to put it).

And is it really better to use "switch" loop or "if" loop (eaven if it is not really a loop). For me they are kind of same with functions and switch is much easyer to use.

tnkass

Re: Application in C# that can be very useful (my first ever)

Posted: Sat Jan 02, 2010 11:35 am
by hurstshifter
EdEown wrote: And is it really better to use "switch" loop or "if" loop (eaven if it is not really a loop). For me they are kind of same with functions and switch is much easyer to use.

tnkass
It will vary. If you are trying to test against several conditions such as "is the number greater than 100 AND is the number less than 200 AND is the number exactly 50" then using an IF-IF Else construct would work for you. If you are expecting only one condition to be met such as when getting a multiple choice answer from a user "Please enter your choice(A,B,C,D):" than using a switch statement would be the best idea as you do not need to check all the conditions.

Re: Application in C# that can be very useful (my first ever)

Posted: Sat Jan 02, 2010 12:41 pm
by EdEown
hurstshifter wrote:
EdEown wrote: And is it really better to use "switch" loop or "if" loop (eaven if it is not really a loop). For me they are kind of same with functions and switch is much easyer to use.

tnkass
It will vary. If you are trying to test against several conditions such as "is the number greater than 100 AND is the number less than 200 AND is the number exactly 50" then using an IF-IF Else construct would work for you. If you are expecting only one condition to be met such as when getting a multiple choice answer from a user "Please enter your choice(A,B,C,D):" than using a switch statement would be the best idea as you do not need to check all the conditions.
okk thanks alot :D