Created
March 21, 2014 18:40
-
-
Save dillmo/9692969 to your computer and use it in GitHub Desktop.
Intro to C++ Test 1 Lab Solution
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
/* Dillon Morse - ASD Intro to C++ Test 1 Lab Solution | |
* --------------------------------------------------- | |
* Write a program that will input an arbitrary number of people who want to | |
* play on a soccer team. We will not accept more than 20 applicants. | |
* | |
* Now determine how many teams of 11 people on a side can we form? | |
* | |
* Full credit requires that you handle incorrect data. | |
*/ | |
#include<iostream> | |
#include<ctime> | |
#include<cstdlib> | |
using namespace std; | |
bool error(int); | |
int num_teams(int); | |
int main() { | |
int num_applicants; | |
int teams; | |
srand(time(NULL)); | |
num_applicants = rand() % 221; | |
if(error(num_applicants)) { | |
cout << "Err: Negative or too many applicants" << '\n'; | |
} else { | |
teams = num_teams(num_applicants); | |
cout << "There can be " << teams << " teams of 11 each" << '\n'; | |
} | |
return 0; | |
// The process is never paused by the kernel because I am using a CLI, so | |
// keeping it active is most convenient. | |
} | |
bool error(int num_applicants) { | |
bool fail; | |
if((num_applicants > 220) || (num_applicants < 0)) { | |
fail = true; | |
} else { | |
fail = false; | |
} | |
return fail; | |
} | |
int num_teams(int applicants) { | |
int teams; | |
teams = applicants / 11; | |
return teams; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment