Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. /********************************************************************
  2.   * Lab 7 : Functions.cpp
  3.   *
  4.   * Author: Esteban Woodring
  5.   *         edw13@zips.uakron.edu
  6.   *
  7.   * Purpose: Introduce concepts of functions
  8.   *
  9.   ********************************************************************/
  10.  
  11. #include <iostream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. // prototypes
  16. int input_an_int();
  17. void print_sequence(int);
  18. string rate_time(int);
  19.  
  20.  
  21. int main() {
  22.     int numb;
  23.     int commute_time;
  24.     string length;
  25.    
  26.     numb = input_an_int();
  27.     print_sequence(numb);
  28.    
  29.     cout << "How long does it take you to get to school?";
  30.     cin >> commute_time;
  31.     length= rate_time(commute_time);
  32.    
  33.     cout << commute_time << " minutes seems " << length;
  34.    
  35.    
  36.    
  37.  
  38.     return 0;
  39. }
  40.  
  41. //New print sequence function
  42. void print_sequence(int v) {
  43.     int n;      // for user input
  44.  
  45.  
  46.     cout << "Sequence from 0 to end\n";
  47.     n = v;
  48.  
  49.     cout << "Sequence from 0 to " << n
  50.             << ": ";
  51.     for(int i=0;i<=n;++i){
  52.         cout << i << " ";
  53.     }
  54.     cout << endl;
  55. }
  56.  
  57.  
  58. // Get user input and try to interpret it as an integer.
  59. int input_an_int() {
  60.     int num = 0;
  61.     cout << "Type an integer, then press enter:\n>" << flush;
  62.     cin >> num;
  63.     cin.ignore(20000, '\n');
  64.     return num;
  65. }
  66.  
  67. //New rate time function
  68. string rate_time(int min) {
  69.  
  70.     if(min > 0 && min <= 30)
  71.         return "short";
  72.     else if( min > 30 && min < 60)
  73.         return "medium";
  74.     else if(min > 60)
  75.         return "long";
  76.     else
  77.         return "impossible";
  78.    
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement