M
Morgan
Hi, newbie coder here
I've been working on this code for about 2 days now, and can't get it
to work. Ultimately I need a algorithm to loop between my pieces of
validation code so that a variable meets 3 different conditions.
I don't want my homework done for me, I would like a system, an
algorithm so I can figure this out. Quite honestly I've tried
everything (very little!) I know, I've functionalised the code, I've
used loops within loops, segmented the code so that the error messages
and validation and input occur separately.
I see what the problem is, obviously the code needs a way of referring
back to the other validation code when a variable succeeds the test I
give it. But I'm all out of ideas :-(
What I have is three while loops, example:
code below:
///////////////////////////////////////////////////////////////////////////
cout << "Please enter the number of judges: ";
cin >> num_judges_float;
num_judges_int = num_judges_float;
while((num_judges_float - num_judges_int) > 0)
{
cout << "\nError: You entered the number of judges with a
decimal point.\n\n";
cout << "Please enter the number of judges with no decimal
point: ";
cin >> num_judges_float;
num_judges_int = num_judges_float;
header();
// just sticks a ascii banner on top of console window
}
while(num_judges_int < 1)
{
// can't have negative judges or zero judges!
cout << "Error: The number of judges cannot be negative or
zero : ";
cout << "\n\nPlease reenter the number of judges : ";
cin >> num_judges_int;
header();
}
while(num_judges_int < 3)
{
/*
We aren't able to compute an average in the case that the number
of judges is 1 or 2. This is because later in this program
we have
to take the highest and lowest scores from the total of
scores.
If we do this we have to divide the remaining total by the
number
of judges minus two to get an average.(two for the two
scores we're
getting rid of). In the case we have two judges, we would wind up
dividing the total into zero (impossible) or in the case that we
had only one judge, we would be dividing the total into a
negative
number which would then give a negative result. As these events
don't lead to an average, it seemed best to me to give the user
an error message to explain what was wrong.
*/
cout << "Sorry, this program cannot give an average if there
is less than three judges";
cout << "\n\nPlease reenter the number of judges : ";
cin >> num_judges_int;
header();
}
Thanks for any help, I'd greatly appreciate it!
I've been working on this code for about 2 days now, and can't get it
to work. Ultimately I need a algorithm to loop between my pieces of
validation code so that a variable meets 3 different conditions.
I don't want my homework done for me, I would like a system, an
algorithm so I can figure this out. Quite honestly I've tried
everything (very little!) I know, I've functionalised the code, I've
used loops within loops, segmented the code so that the error messages
and validation and input occur separately.
I see what the problem is, obviously the code needs a way of referring
back to the other validation code when a variable succeeds the test I
give it. But I'm all out of ideas :-(
What I have is three while loops, example:
code below:
///////////////////////////////////////////////////////////////////////////
cout << "Please enter the number of judges: ";
cin >> num_judges_float;
num_judges_int = num_judges_float;
while((num_judges_float - num_judges_int) > 0)
{
cout << "\nError: You entered the number of judges with a
decimal point.\n\n";
cout << "Please enter the number of judges with no decimal
point: ";
cin >> num_judges_float;
num_judges_int = num_judges_float;
header();
// just sticks a ascii banner on top of console window
}
while(num_judges_int < 1)
{
// can't have negative judges or zero judges!
cout << "Error: The number of judges cannot be negative or
zero : ";
cout << "\n\nPlease reenter the number of judges : ";
cin >> num_judges_int;
header();
}
while(num_judges_int < 3)
{
/*
We aren't able to compute an average in the case that the number
of judges is 1 or 2. This is because later in this program
we have
to take the highest and lowest scores from the total of
scores.
If we do this we have to divide the remaining total by the
number
of judges minus two to get an average.(two for the two
scores we're
getting rid of). In the case we have two judges, we would wind up
dividing the total into zero (impossible) or in the case that we
had only one judge, we would be dividing the total into a
negative
number which would then give a negative result. As these events
don't lead to an average, it seemed best to me to give the user
an error message to explain what was wrong.
*/
cout << "Sorry, this program cannot give an average if there
is less than three judges";
cout << "\n\nPlease reenter the number of judges : ";
cin >> num_judges_int;
header();
}
Thanks for any help, I'd greatly appreciate it!