Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Written by: Fredi Garcia
  2. //Assignment: In Class Final
  3. //Class: CoSci 243
  4. //Date: 6/1/2017
  5. //Description: This program takes in measurements in inches that are input by the user
  6. // the program then runs through three functions that output to the screen the
  7. // conversions to meters and yards
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. void description();//description
  13. void getInfo (int a[], int& num);//get input
  14. void displayInches (int a[], int num);//displays inches
  15. void displayMeters (int a[], int num, double& meters);//displays meters
  16. void displayYards (int a[], int num, double& yards);//displays yards
  17.  
  18. int main()
  19. {
  20. int measurements[10];
  21. int inches, spacesUsed;
  22. double meters, yards;
  23.  
  24. description();//calling description
  25. getInfo(measurements, spacesUsed);//getting the inout
  26.  
  27. displayInches(measurements, spacesUsed);//invoking the inches to be displayed
  28.  
  29. cout.setf(ios::fixed);
  30. cout.setf(ios::showpoint);
  31. cout.precision(4);
  32.  
  33. displayMeters(measurements, spacesUsed, meters);//invoking to show meters
  34. displayYards (measurements, spacesUsed, yards);//invoking to show yards
  35.  
  36. return 0;
  37. }
  38. void description()//description
  39. {
  40. cout << "This program will allow you to convert inches to meters and yards.\n";
  41. }
  42. void getInfo (int a[], int& num)//gets inches
  43. {
  44. int inches;
  45.  
  46. num = 0;
  47.  
  48. cout << "\nPlease enter up to ten measurements in inches. (when you are done enter -1)\n";
  49.  
  50. while (inches >= 0 && num < 10)
  51. {
  52. cin >> inches;
  53. a[num] = inches;
  54. num++;
  55. }
  56. }
  57. void displayInches (int a[], int num)//displays the input
  58. {
  59. cout << "\n\nValues in inches:\n";
  60. for (int i = 0; i < num-1; i++)
  61. cout << endl << a[i];
  62. }
  63. void displayMeters (int a[], int num, double& meters)//converts inches to meters and outputs
  64. {
  65. cout << "\n\nValues in meters:\n";
  66. for (int i = 0; i < num-1; i ++)
  67. {
  68. meters = (a[i]/39.3700787);
  69. cout << endl << meters;
  70. }
  71. }
  72. void displayYards(int a[], int num, double& yards)//converts inches to yards and outputs
  73. {
  74. cout << "\n\nValues in yards:\n";
  75. for (int i = 0; i < num - 1; i++)
  76. {
  77. yards = (a[i]/36);
  78. cout << endl << yards;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement