Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. /********************************************************************
  2.   * Lab 7 : Functions.cpp
  3.   *
  4.   * Author: Alissa McGill
  5.   *         alm161@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_type(int);
  19.  
  20. int main()
  21. {
  22.     int n, t, r;      // for user input
  23.  
  24.  
  25.     cout << "Sequence from 0 to end\n";
  26.     n = input_an_int();
  27.    
  28.     print_sequence(n);
  29.     cout << endl;
  30.    
  31.     cout<<"Type in a commute time (in minutes): "<<endl;
  32.     t = input_an_int();
  33.     rate_time(t);
  34.    
  35.     cout<<t<< "minutes seems" <<rate_time(t)<<endl;
  36.  
  37.     return 0;
  38. }
  39.  
  40. // Get user input and try to interpret it as an integer.
  41. int input_an_int() {
  42.     int num = 0;
  43.     cout << "Type an integer, then press enter:\n>" << flush;
  44.     cin >> num;
  45.     cin.ignore(20000, '\n');
  46.     return num;
  47. }
  48.  
  49. void print_sequence(int x)
  50. {
  51.     int n;
  52.     n=x;
  53.     cout << "Sequence from 0 to " << x<< ": ";
  54.    
  55.     for(int i =0; i<=x ; ++i)
  56.     {
  57.         cout << i << " ";
  58.     }
  59. }
  60.  
  61. string rate_time(int r)
  62. {
  63.     int t;
  64.     t=r;
  65.    
  66.     if (r<=30)
  67.         t='short';
  68.     else if(r>30 && r<60)
  69.         t='medium';
  70.     else if(r>=60)
  71.         t='long';
  72.     else
  73.         t='impossible';
  74.     return t;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement