-
November 15th, 2014, 10:10 AM
#1
Student looking for help with a code
Hi everyone. I am new here so I looking forward to meeting all of you. I am a college student and I am having trouble with this code I wrote. The main loop I wrote works just fine but I wrote a nested loop and I am obviously missing something simple to get it to work but I can't figure out what it is. I'm thinking a second set of eyes may help me. Thank you for all the help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Welcome statment
Console.WriteLine("Welcome contestants and judges");
Console.WriteLine("Time to see what these divers can do");
//Declare variable
string moreDivers = "Y";
do
{
//Declare variables
double sum = 0, score = 0, totalScore = 0, difficulty = 0, diffScore = 0, high = -1, low = 11, average = 0;
string diversName, city;
//Get input from user
Console.WriteLine("Please enter the diver's name");
diversName = Console.ReadLine();
Console.WriteLine("Please enter the city the diver is from");
city = Console.ReadLine();
Console.WriteLine("Now it is time to get the judges scores");
int num = 1;
while ( num < 6)
{
Console.WriteLine("Please enter a score between 1 and 10 for the diver judge " + num);
score = double.Parse(Console.ReadLine());
while (score < -1 || score > 11)
{
Console.WriteLine("Please enter a valid score");
Console.WriteLine("Please enter a score between 1 and 10 for the diver judge " + num);
score = double.Parse(Console.ReadLine());
}
Console.WriteLine("Please enter the degree of difficulty");
difficulty = double.Parse(Console.ReadLine());
while (difficulty < 0 || difficulty > 1.68)
{
Console.WriteLine("Please enter a valid degree");
Console.WriteLine("Please enter the degree of difficulty");
difficulty = double.Parse(Console.ReadLine());
}
//Test high and low values
if (score > high)
{
high = score;
}
if (score < low)
{
low = score;
}
//Do calculations
sum += score;
diffScore += difficulty;
totalScore = (sum - low - high) / 3 * diffScore;
average = sum / 5;
//Display output
Console.WriteLine(diversName + " Your highest score is {0} and your lowest score was {1}", high, low);
Console.WriteLine(diversName+ " Your total score is {0}", totalScore);
Console.WriteLine(diversName + " Your average score is {0}", average);
Console.WriteLine("Do you wish to enter another diver?");
moreDivers = Console.ReadLine();
}
while (moreDivers == "Y" || moreDivers == "y");
Console.ReadLine(); //This last line of code it to keep the program open
}
}
}
-
November 15th, 2014, 12:54 PM
#2
Re: Student looking for help with a code
Welcome to the Forums!
Please use CODE TAGS to format your code. (Advanced view #)
Also, try using F8 to step thru your code, or else put a breakpoint F9 at your main loop and then us F8. It should help greatly to discover what your code IS doing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|