fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. float startingNum;
  6. int numOfDays;
  7. float dailyRate;
  8. float dailyPct;
  9. float increaseAmt;
  10.  
  11. cout << "Enter the starting number of poplation\n";
  12. cin >> startingNum;
  13.  
  14. while (startingNum < 2)
  15. {
  16. cout << "Only enter number that is 2 or more.\n";
  17. cin >> startingNum;
  18. }
  19.  
  20. cout << "Enter the daily rate for the multiplication. Write 10 if its 10%.\n";
  21. cin >> dailyRate;
  22.  
  23. while (dailyRate < 0)
  24. {
  25. cout << "Only enter postive number\n";
  26. cin >> dailyRate;
  27. }
  28.  
  29. cout << "Enter the number of days\n";
  30. cin >> numOfDays;
  31.  
  32. while (numOfDays < 1)
  33. {
  34. cout << "Only enter number 1 or that is greater than 1.\n";
  35. cin >> numOfDays;
  36. }
  37.  
  38. dailyPct = dailyRate/100;
  39.  
  40. cout << "Size of population for day 1 :" << startingNum << endl;
  41.  
  42. for (int i = 2 ; i <= numOfDays ; i++)
  43. {
  44. increaseAmt = dailyPct * startingNum;
  45. startingNum += increaseAmt;
  46.  
  47. cout << "Size of population for day " << i << " :";
  48. cout << startingNum << endl;
  49.  
  50. }
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5272KB
stdin
10
200
4
stdout
Enter the starting number of poplation
Enter the daily rate for the multiplication. Write 10 if its 10%.
Enter the number of days
Size of population for day 1 :10
Size of population for day 2 :30
Size of population for day 3 :90
Size of population for day 4 :270