Created
May 17, 2012 18:38
-
-
Save brand-it/2720815 to your computer and use it in GitHub Desktop.
Average system for loop and stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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