Author Topic: Learing C#  (Read 1262 times)

0 Members and 1 Guest are viewing this topic.

Offline dxromTopic starter

  • Master of the milestones!
  • Elite
  • *
  • *
  • Posts: 1070
  • Activity:
    0%
  • Reputation Power: 14
  • dxrom barely matters.dxrom barely matters.
  • KEYBOARD COWBOY, GREAT SAMURAI OF THE INTERNET.
  • Respect: 0
  • Referrals: 1
    • View Profile
Learing C#
« on: November 18, 2012, 09:15:14 PM »
0
So, I'm in my third, almost fourth week of a C# course for college and this week we played around with Loops, I wrote a program for class (The topic was given out by the teacher and was the same for everyone). I think it turned out well, but after reading through some class mate's posts I'm wondering if it could have been better (Note, we're not aloud to use arrays, only simple loops). Because I notice alot of students complaining about having to use a lot of Break; Continue; statements in order to leave the loop. My program however didn't utilize any. I'll toss up source for input.

Code: [Select]
// ---------------------------------------------------------------
// Programming Assignment:    LAB3A
// Developer:                 MP
// Date Written:              November 18, 2012
// Purpose:                   Diver's Score Calculator
// ---------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LAB3A
{
    class Program
    {
        static void Main(string[] args)
        {
            do
            {
                //vars
                double rating, score, scoreTotal = 0, highScore = 0, lowScore = 10, dedScore = 0;
                string dName, dHome;

                //Prompt for name/city/rating
                Console.Write("Diver's Name: ");
                dName = Console.ReadLine();
                Console.Write("Diver's City: ");
                dHome = Console.ReadLine();
                //rating stuff
                Console.Write("Dive degree of difficulty: ");
                rating = Double.Parse(Console.ReadLine());
                while (rating < 1 || rating > 1.67)
                {
                    Console.WriteLine("Invalid degree of difficulty - Please reenter (Valid Range: 1 - 1.67)");
                    Console.Write("Dive degree of difficulty: ");
                    rating = Double.Parse(Console.ReadLine());
                }
                //Judge Scoring
                for (int i = 1; i <= 5; i++)
                {
                    Console.WriteLine("Judge #{0} score: ", i);
                    score = Double.Parse(Console.ReadLine());
                    while (score < 0 || score > 10)
                    {
                        Console.WriteLine("Invalid score - Please reenter (Valid Range: 0 - 10)");
                        Console.WriteLine("Judge #{0} score: ", i);
                        score = Double.Parse(Console.ReadLine());
                    }
                    if (score > highScore)
                    {
                        highScore = score;
                    }
                    if (score < lowScore)
                    {
                        lowScore = score;
                    }
                    scoreTotal = score + scoreTotal;
                }
                dedScore = highScore + lowScore;
                scoreTotal = (scoreTotal - dedScore) / 3 * rating;
                //Display stuffs
                Console.WriteLine("Diver: {0}", dName);
                Console.WriteLine("City: {0}", dHome);
                Console.WriteLine("Dive Score: {0}", scoreTotal);
                Console.WriteLine("Do you want to process another diver (Y/N)?");
            } while (Console.ReadLine().ToUpper() != "N");
            break;
        }
    }
}



 ​_██​_
(ಠ​_ృ)
I do say, ol' Chap! Come play EVE Online! Why here is a 21 Day Free Trial!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 12884
  • Activity:
    0%
  • Reputation Power: 149
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Jesse
  • Respect: +21
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: Learing C#
« Reply #1 on: November 19, 2012, 07:07:14 AM »
0
Those complainers are ones that are also against gotos.  They are only happy when execution flow terminates in a "controlled" way.  I've always felt that if a tool is in the toolbox, you might give it a whirl.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline dxromTopic starter

  • Master of the milestones!
  • Elite
  • *
  • *
  • Posts: 1070
  • Activity:
    0%
  • Reputation Power: 14
  • dxrom barely matters.dxrom barely matters.
  • KEYBOARD COWBOY, GREAT SAMURAI OF THE INTERNET.
  • Respect: 0
  • Referrals: 1
    • View Profile
Re: Learing C#
« Reply #2 on: November 19, 2012, 10:48:45 AM »
0
Well, I got full credit for it. So I assume it was done correctly :D



 ​_██​_
(ಠ​_ృ)
I do say, ol' Chap! Come play EVE Online! Why here is a 21 Day Free Trial!

Offline Crome969

  • RebirthUO - Developer
  • Elite
  • *
  • *
  • Posts: 2075
  • Activity:
    1.6%
  • Reputation Power: 24
  • Crome969 might someday be someone...Crome969 might someday be someone...Crome969 might someday be someone...Crome969 might someday be someone...
  • Gender: Male
  • StealthUO - Developer
  • Respect: 0
  • Referrals: 9
    • View Profile
    • RebirthUO - UO Freeshard
Re: Learing C#
« Reply #3 on: November 23, 2012, 06:50:56 AM »
0
Instead of twice using if you could use
Code: [Select]
if(statement){...}else if(statement){}Think on rtc applications the double jumping in if statement could decrease performance... But i think the flow of your code is good.. Nothing to complain :)

Tags: