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

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
EdEown
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Dec 19, 2009 5:00 pm
Favorite Gaming Platforms: PS3
Programming Language of Choice: C#
Location: Bosnia and Herzegovina

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

Post 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
"There is nothing either good or bad, but our thinking makes it so"
User avatar
Lord Pingas
Chaos Rift Regular
Chaos Rift Regular
Posts: 178
Joined: Thu Dec 31, 2009 9:33 am
Favorite Gaming Platforms: NES, SNES, Nintendo 64, Dreamcast, Wii
Programming Language of Choice: C++
Location: Hiding In My Mum's Basement With My Pokemon Cards

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

Post by Lord Pingas »

Well done on your first program :)
User avatar
avansc
Respected Programmer
Respected Programmer
Posts: 1708
Joined: Sun Nov 02, 2008 6:29 pm

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

Post by avansc »

not bad. but you might wanna make separate functions for easy calculation.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
User avatar
GroundUpEngine
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 835
Joined: Sun Nov 08, 2009 2:01 pm
Current Project: mixture
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Location: UK

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

Post by GroundUpEngine »

Looks great 8-)
EdEown
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Dec 19, 2009 5:00 pm
Favorite Gaming Platforms: PS3
Programming Language of Choice: C#
Location: Bosnia and Herzegovina

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

Post 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:
"There is nothing either good or bad, but our thinking makes it so"
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

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

Post 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.
EdEown
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Dec 19, 2009 5:00 pm
Favorite Gaming Platforms: PS3
Programming Language of Choice: C#
Location: Bosnia and Herzegovina

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

Post 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
"There is nothing either good or bad, but our thinking makes it so"
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

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

Post 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.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
EdEown
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 30
Joined: Sat Dec 19, 2009 5:00 pm
Favorite Gaming Platforms: PS3
Programming Language of Choice: C#
Location: Bosnia and Herzegovina

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

Post 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
"There is nothing either good or bad, but our thinking makes it so"
Post Reply