Advertisement
Guest User

Dailies 3

a guest
Apr 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.46 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <fstream>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.  
  12.     float weight;
  13.     float height;
  14.     cout << "In pounds, how much do you weigh?" << endl;
  15.     cin >> weight;
  16.     cout << "In inches, how tall are you?" << endl;
  17.     cin >> height;
  18.     float bmi = (weight * .45) / pow((height * .025), 2);
  19.     cout << "BMI: " << bmi << endl;
  20.  
  21.     if (bmi >= 40) { cout << "Category: Obese Class III (very severely obese)" << endl; }
  22.     else if (bmi >= 35) { cout << "Category: Obese Class II (severely obese)" << endl; }
  23.     else if (bmi >= 30) { cout << "Category: Obese Class I (moderately obese)" << endl; }
  24.     else if (bmi >= 25) { cout << "Category: Overweight" << endl; }
  25.     else if (bmi >= 18.5) { cout << "Category: Normal (healthy weight)" << endl; }
  26.     else if (bmi >= 16) { cout << "Category: Underweight" << endl; }
  27.     else if (bmi >= 15) { cout << "Category: Severely Underweight" << endl; }
  28.     else { cout << "Category: Very Severely Underweight" << endl; };
  29.     cout << "---------- End of Daily 1 ----------\n\n\n";
  30.  
  31.  
  32.     string eightQ;
  33.     string repeatQ;
  34.     string response1 = "It is certain";
  35.     string response2 = "It is decidedly so";
  36.     string response3 = "Reply hasy try again";
  37.     string response4 = "Ask again later";
  38.     string response5 = "Don't count on it";
  39.     string response6 = "Very doubtful";
  40.     do
  41.     {
  42.         srand(time(NULL));
  43.         int randomNumber = rand() % 6 + 1;
  44.  
  45.         cout << "What would you like to know? Please ask the Magic 8-Ball a yes or no question." << endl;
  46.         cin >> eightQ;
  47.         switch (randomNumber)
  48.         {
  49.         case 1: cout << response1 << endl;
  50.             break;
  51.         case 2:    cout << response2 << endl;
  52.             break;
  53.         case 3:    cout << response3 << endl;
  54.             break;
  55.         case 4:    cout << response4 << endl;
  56.             break;
  57.         case 5:    cout << response5 << endl;
  58.             break;
  59.         case 6: cout << response6 << endl;
  60.             break;
  61.         }
  62.         cout << "Do you wish to play again?";
  63.         cin >> repeatQ;
  64.  
  65.     } while (repeatQ != "quit");
  66.     cout << "---------- End of Daily 2 ----------\n\n\n";
  67.  
  68.  
  69.     float loanAmount;
  70.     int loanTerm;
  71.     float annualRate;
  72.  
  73.     cout << "What is your loan amount?" << endl;
  74.     cin >> loanAmount;
  75.     cout << "What is your annual interest rate? (.##)" << endl;
  76.     cin >> annualRate;
  77.     cout << "What is your loan term in months?" << endl;
  78.     cin >> loanTerm;
  79.     float monthlyPayment = ((annualRate / 12) * loanAmount * pow((1 + (annualRate / 12)), loanTerm)) / (pow((1 + (annualRate / 12)), loanTerm) - 1);
  80.     cout << "Monthly Payment Amount: " << monthlyPayment << endl;
  81.  
  82.     for (size_t i = 0; i < loanTerm; i++)
  83.     {
  84.  
  85.         float interest = (annualRate / 12) * loanAmount;
  86.         float principal = monthlyPayment - interest;
  87.         float balance = loanAmount - principal;
  88.  
  89.         cout << "Principal #: " << i + 1 << " " << principal << " Interest: " << interest << " Balance: " << balance << endl;
  90.         loanAmount = balance;
  91.     };
  92.     cout << "---------- End of Daily 3 ----------\n\n\n";
  93.  
  94.  
  95.  
  96.     string playagain;
  97.     int guess;
  98.     do
  99.     {
  100.         srand(time(NULL));
  101.         int randomN100 = rand() % 100 + 1;
  102.         cout << "I'm thinking of a number between 1 and 100...\n\n";
  103.  
  104.         do
  105.         {
  106.             cout << "Guess: ";
  107.             cin >> guess;
  108.  
  109.             if (guess > randomN100) cout << "Your guess is too high.\n";
  110.             if (guess < randomN100) cout << "Your guess is too low.\n";
  111.  
  112.         } while (guess != randomN100);
  113.  
  114.         cout << "Your guess is correct!\n\n";
  115.         cout << "Do you wish to play again? ";
  116.         cin >> playagain;
  117.  
  118.     } while (playagain != "quit");
  119.     cout << "---------- End of Daily 4 ----------\n\n\n";
  120.  
  121.  
  122.     ifstream rainSheet;
  123.     float dailyRain;
  124.     float totalRain = 0;
  125.     rainSheet.open("C:\\Users\\cis.LABS\\Downloads\\rainfall.txt", ios::in);
  126.     rainSheet >> dailyRain;
  127.     int i = 0;
  128.     while (!rainSheet.eof() && dailyRain != -999)
  129.     {
  130.         if ( dailyRain >= 0)
  131.         {
  132.             i++;
  133.             totalRain +=dailyRain;
  134.         }
  135.        
  136.         rainSheet >> dailyRain;
  137.     }
  138.     cout << "Average rain over " << i << " days is: " << totalRain / i << endl;
  139.     cout << "---------- End of Daily 5 ----------\n\n\n";
  140.  
  141.  
  142.  
  143.     system("pause");
  144.     return 0;
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement