Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********************************************************************
- * Lab 7 : Functions.cpp
- *
- * Author: Esteban Woodring
- * edw13@zips.uakron.edu
- *
- * Purpose: Introduce concepts of functions
- *
- ********************************************************************/
- #include <iostream>
- #include <string>
- using namespace std;
- // prototypes
- int input_an_int();
- void print_sequence(int);
- string rate_time(int);
- int main() {
- int numb;
- int commute_time;
- string length;
- numb = input_an_int();
- print_sequence(numb);
- cout << "How long does it take you to get to school?";
- cin >> commute_time;
- length= rate_time(commute_time);
- cout << commute_time << " minutes seems " << length;
- return 0;
- }
- //New print sequence function
- void print_sequence(int v) {
- int n; // for user input
- cout << "Sequence from 0 to end\n";
- n = v;
- cout << "Sequence from 0 to " << n
- << ": ";
- for(int i=0;i<=n;++i){
- cout << i << " ";
- }
- cout << endl;
- }
- // Get user input and try to interpret it as an integer.
- int input_an_int() {
- int num = 0;
- cout << "Type an integer, then press enter:\n>" << flush;
- cin >> num;
- cin.ignore(20000, '\n');
- return num;
- }
- //New rate time function
- string rate_time(int min) {
- if(min > 0 && min <= 30)
- return "short";
- else if( min > 30 && min < 60)
- return "medium";
- else if(min > 60)
- return "long";
- else
- return "impossible";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement