Click here to Skip to main content
15,896,439 members
Please Sign up or sign in to vote.
1.75/5 (4 votes)
See more:
C#
{
            string diverName;
            string city;
            double score;
            double total_score;
            double final_score = 0;
            double difficulty;
            double highest;
            double lowest;
            double overall;
            sbyte process_diver;
            int judge_ctr;
            int num_divers = 0;

            Console.Write("Report to the media\n");
            Console.Write("Event: Diving competition\n\n");

            do
            {
                Console.Write("{0:F2}", "Enter the diver's name: ");
                Console.WriteLine("diverName");

                Console.Write("{0:F2}", "Enter the diver's city: ");
                Console.WriteLine("city");

                highest = -1;
                lowest = 11;
                total_score = 0;
                judge_ctr = 1;
                do
                {
                    Console.Write("{0:F2}", "Enter the score given by judge #");
                    Console.Write("{0:F2}", judge_ctr);
                    Console.Write("{0:F2}", ": ");
                    score = Convert.ToInt32(Console.ReadLine());

                    if (score <= 0 || score >= 11)
                    {
                        Console.Write("{0:F2}", "Values must be between 0 and 10.");
                        Console.Write("{0:F2}", "Enter the score given by judge # ");
                        Console.Write("{0:F2}", judge_ctr);
                        Console.Write("{0:F2}", ": ");
                        score = Convert.ToInt32(Console.ReadLine());
                    }

                    total_score += score;
                    judge_ctr++;

                }
                while (judge_ctr <= 5);

                Console.Write("{0:F2}", "Enter between 1.0 and 1.67 inclusive.");
                Console.Write("{0:F2}", "\n");
                Console.Write("{0:F2}", "What was the degree of difficulty? ");
                score = Convert.ToInt32(Console.ReadLine());

                if (difficulty <= (0.9) || difficulty >= (1.68)) ;
                {
                    Console.Write("{0:F2}", "Invalid range. Choose between 1.0 and 1.67");
                    Console.Write("{0:F2}", "What was the degree of difficulty? ");
                    score = Convert.ToInt32(Console.ReadLine());
                }

                score = (total_score - lowest - highest) / 3 * difficulty;

                Console.Write("{0:F2}", "Diver: ");
                Console.Write("{0:F2}", diverName);
                Console.Write("{0:F2}", ", City: ");
                Console.Write("{0:F2}", city);
                Console.Write("{0:F2}", "\n");
                final_score = final_score + overall;
                num_divers = num_divers + 1;
                Console.Write("{0:F2}", "Overall  score was ");
                Console.Write("{0:F2}", final_score);
                Console.Write("{0:F2}", ".");
                Console.Write("{0:F2}", "\n");
                Console.Write("{0:F2}", "\nDo you want to process another diver (Y/N)? ");
                score = Convert.ToInt32(Console.ReadLine());
                process_diver = sbyte.Parse("process_diver");

                Console.WriteLine("50\n'");

            }
            while (process_diver == 'Y' || process_diver == 'y');

            Console.Write("{0:F2}", "EVENT SUMMARY\n");
            Console.Write("{0:F2}", "Number of divers participating: ");
            Console.Write("{0:F2}", num_divers);
            Console.Write("{0:F2}", "\n");
            Console.Write("{0:F2}", "Average score of all divers: ");
            Console.Write("{0:F2}", final_score / num_divers);
            Console.Write("{0:F2}", "\n");

            Console.WriteLine("\n\nPress any key to continue...");
            Console.ReadLine();
Posted
Updated 21-May-11 16:26pm
v2
Comments
Wonde Tadesse 21-May-11 21:21pm    
Do you know full code block ? public void myfunction(){ // blah blah blah ...}
Matt Bratton 23-May-11 3:36am    
Not that all well. Just in my 4th weeks of class.
Wonde Tadesse 23-May-11 7:27am    
See NuttingCDEF answer. It's clearly explained.
Kim Togo 22-May-11 2:10am    
Code dump.. Please be more specific what and where your problem is in the code.

Warning 1 Possible mistaken empty statement 72 66 Lab3A


Error 2 Use of unassigned local variable 'difficulty' 72 21 Lab3A


Error 3 Use of unassigned local variable 'diverName'
82 41 Lab3A

Error 4 Use of unassigned local variable 'city'
84 41 Lab3A


Error 5 Use of unassigned local variable 'overall'
86 45 Lab3A

This is only my 3rd week in C#. And I'm not a pro. This is everything it is telling me right now that is wrong. Want happen was I had someone help me after class. And he was telling me thinks I didn't know yet. Then after that he forgot I was in C# and was talking about C++. So this is how far I got. Thanks so far for all the help. I hope this will help.
 
Share this answer
 
Comments
Dalek Dave 22-May-11 6:25am    
Nice.
NuttingCDEF 22-May-11 14:01pm    
Matt - see my solution.

And a Hint for the future - if you need to provide more info, don't post it as a solution, just edit your original question.
You have lots of Console.Write() statements that really don't make any sense, including some with redundant formatting fields. Go back to your notes and think about what you are trying to achieve at those points in the code. If you are trying to get some information from the user then you probably need some form of Read rather than a Write.
 
Share this answer
 
Comments
Dalek Dave 22-May-11 6:26am    
Sage advice.
Richard MacCutchan 22-May-11 7:34am    
I thought you'd be in the pub crying all day. Or do you use CP as therapy? :)
NuttingCDEF 22-May-11 14:01pm    
Agree - my 5
Matt


Sounds like you might be trying to run before you can walk. So take this slowly . . . I'm not quite sure what stage you're at, so start at the beginning (with apologies if the first 2 or 3 points are too basic).

1. I presume you've created a C# Windows Console application in some version of Visual Studio

2. Have you got a Hello World application to work? If not, see:
http://msdn.microsoft.com/en-us/library/k1sx6ed2(v=vs.71).aspx[^]
and get the up and running.

3. Now start replacing the

MIDL
System.Console.WriteLine("Hello World!");


line between the braces
C#
{
}

with your code.

Suggest you do this adding one / a few lines at a time.
At each stage, compile it, sort out any problems, test that it does what you expect, debug it before moving on.

Make sure you understand EXACTLY what every single line does - even every character - computers have the delightful / infuriating habit of doing exactly what they are told - to the letter - neither more nor less - even the best can get caught by what, with hindsight, are trivial errors.

4. See Richard MacCutchan's solution
You have things like:
MIDL
Console.WriteLine("diverName");

but then nothing to Read in any input from the user. If you don't tell the computer to read some input, it won't.

5. Looking at your compiler errors - possible mistaken empty statement
C#
if (difficulty <= (0.9) || difficulty >= (1.68)) ;

The semicolon at the end is wrong. 'if' either has a single statement or a block of statements in braces

if(condition) statement;


if(condition)
{
statements
}


6. Use of unassigned local variable 'difficulty' (and others similarly)

Same line as above - you are using the variable called 'difficulty' before you've assigned a value to it. You've declared it near the top - but until you assign some value to it you can't meaningfully use it. See my point 4. above - I think you mean to Read a value into it from the Console.

Remember - those compiler errors are there to help you - they often aren't exactly in plain English, but can (usually) be worked out with a bit of thought and effort. They should give you the line number that's causing the problem (or sometimes the following line which can be confusing) and often the character on the line. Visual Studio tends to be very good at helping you locate the problem point in your code (double-click the error message!). For more help you can also click the error message and then press F1 to get context help on that specific error - which may explain what the problem is. failing that, Googling the error message can be enlightening.

If after all that you hit an error that really has you stumped, post a question here, with the code, the error and details of which line is causing the error.

Best of luck!
 
Share this answer
 
Comments
Matt Bratton 23-May-11 3:31am    
Thank you so much. This is my only, well I'm in my 4th week now of class in C#. I reworked the first part and it works now. Its the last part I'm still having probs on. But Still working I have tomorrow it get it done.
Richard MacCutchan 23-May-11 3:39am    
Excellent response, my 5.
Wonde Tadesse 23-May-11 7:25am    
Nice answer. My 5 :)
All sorts of issues here. For a start, you have if blocks so if someone enters a bad value twice, it will be accepted. You don't say what output you expect, what is going wrong, I suggest you crack open a book, dig deeper and come back with a specific question, with an intelligent subject line.
 
Share this answer
 
Using the pseudocode below, write the code that will meet the requirements:
Write report heading
Loop as long as there are divers to process
Input diver's name and city
Initialize highest score, lowest score, and total score

Using a do-while loop input the five judges’ scores
Validate the score to ensure it is between 0 and 10
Add score to total
Determine highest and lowest scores

Input and validate the degree of difficulty
Calculate the overall diver's score
Display the diver's information and overall score
Add diver's overall score to the final score
Add 1 to the number of divers
Prompt the user if he or she wants to process another diver
End-Loop
Calculate the average score for all divers
Display the number of divers and the average score for all divers

This is the new code, I know its still not all right but 4 weeks guys I'm not a pro. I'm now at the part where is starts this line "overall = (total_score - lowest - highest) / 3 * difficulty;" still having some probs there.

double score;
double total_score;
double final_score = 0;
double difficulty;
double highest;
double lowest;
double overall;
char process_diver;
int judge_ctr;
int num_divers = 0;

Console.Write("Report to the media\n");
Console.Write("Event: Diving competition\n\n");
do
{
Console.Write("{0:F2}", "Enter the diver's name: ");
Console.Write("{0:F2}", "Enter the diver's city: ");
Console.ReadLine();
highest = -1;
lowest = 11;
total_score = 0;
judge_ctr = 1;
do
{
Console.Write("{0:F2}", "Enter the score given by judge #");
Console.Write("{0:F2}", judge_ctr);
Console.Write("{0:F2}", ": ");
score = double.Parse(Console.ReadLine());
if (score <= 0 || score >= 11)
{
Console.Write("{0:F2}", "Values must be between 0 and 10.");
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "Enter the score given by judge #");
Console.Write("{0:F2}", judge_ctr);
Console.Write("{0:F2}", ": ");
score = Convert.ToInt32(Console.ReadLine());

}
total_score += score;
(judge_ctr)++;
}
while (judge_ctr <= 5);
Console.Write("{0:F2}", "Enter between 1.0 and 1.67 inclusive.");
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "What was the degree of difficulty? ");
difficulty = double.Parse(Console.ReadLine());
if (difficulty <= 0.9 || difficulty >= 1.68)
{
Console.Write("{0:F2}", "Invalid range. Choose between 1.0 and 1.67");
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "What was the degree of difficulty? ");
difficulty = Convert.ToInt32(Console.ReadLine());
Console.Write("{0:F2}", "Invalid range. Choose between 1.0 and 1.67");
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "What was the degree of difficulty? ");
difficulty = Convert.ToInt32(Console.ReadLine());


}
overall = (total_score - lowest - highest) / 3 * difficulty;
Console.Write("{0:F2}", "Diver: ");
Console.Write("{0:F2}", ", City: ");
Console.Write("{0:F2}", "\n");
final_score = final_score + overall;
num_divers = num_divers + 1;
Console.Write("{0:F2}", "Overall score was ");
Console.Write("{0:F2}", final_score);
Console.Write("{0:F2}", ".");
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "\nDo you want to process another diver (Y/N)? ");
process_diver = char.Parse(Console.ReadLine());
}
while (process_diver == 'Y' || process_diver == 'y');
Console.Write("{0:F2}", "EVENT SUMMARY\n");
Console.Write("{0:F2}", "Number of divers participating: ");
Console.Write("{0:F2}", num_divers);
Console.Write("{0:F2}", "\n");
Console.Write("{0:F2}", "Average score of all divers: ");
Console.Write("{0:F2}", final_score / num_divers);
Console.Write("{0:F2}", "\n");
Console.ReadLine();
Console.WriteLine("\n\nPress any key to continue...");
Console.ReadLine();
}
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900