Skip to content

Instantly share code, notes, and snippets.

@brand-it
Created May 17, 2012 18:38
Show Gist options
  • Save brand-it/2720815 to your computer and use it in GitHub Desktop.
Save brand-it/2720815 to your computer and use it in GitHub Desktop.
Average system for loop and stuff
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int total_judges = 0;
double total_number = 0;
double judges[5];
string name, city;
int drivers = 0;
float difficulty;
bool rangecheck(double range, double min = 0, double max = 10){
if(range >= min && range <= max){
return true;
} else {
return false;
}
}
void main() {
setprecision(2);
int judge = 0;
bool valid_range = true;
bool again = true;
string again_str = "n";
while(again){
drivers += 1;
cout << "Please put in your name: ";
getline(cin, name);
cout << "Please put in the city: ";
getline(cin, city);
for (judge = 0; judge < 5; judge++){
valid_range = true;
cout << "Enter the score given by judge #" << judge + 1 << ": ";
cin >> judges[judge];
while(valid_range){
if (rangecheck(judges[judge])){
valid_range = false;
total_judges += 1;
} else {
cout << "The number has to be with in 0 to 10 please try again" << endl;
cout << "Enter the score given by judge #" << judge + 1 << ": ";
cin >> judges[judge];
}
}
}
cout << "What was the degree of difficulty? ";
cin >> difficulty;
valid_range = true;
while(valid_range){
if (rangecheck(difficulty, 1, 1.67)){
valid_range = false;
} else {
cout << "Invalid degree of difficulty - Please reenter (Valid Range: 1 - 1.67): ";
cin >> difficulty;
}
}
cout << "Diver: " << name << " " << city << endl;
for (judge = 0; judge < 5; judge++){
total_number += judges[judge];
}
cout << "Overall score was " << total_number / total_judges << endl;
cout << "Do you want to do this again? ";
cin >> again_str;
if (again_str == "n"){
again = false;
}
cout << "Number of divers participating: " << drivers << endl;
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment