Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct testCase {
  5.     double rate;
  6.     double balence;
  7.     double payment;
  8. };
  9.  
  10. //Function Prototypes
  11. void inputCases(testCase* myCases,int n);
  12. void outputResults(testCase* myCases,int n);
  13.  
  14. int main() {
  15.     int numOfCases;
  16.     cin>>numOfCases;
  17.     testCase* myCases=new testCase[numOfCases];
  18.     inputCases(myCases,numOfCases);
  19.     outputResults(myCases,numOfCases);
  20.     return 0;
  21. }
  22.  
  23. //Function Definitions
  24. void inputCases(testCase* myCases,int n) {
  25.     for(int i=0; i < n; i++)
  26.         cin>>myCases[i].rate>>myCases[i].balence>>myCases[i].payment;
  27. }
  28.  
  29. void outputResults(testCase* myCases,int n) {
  30.     for(int i=0; i < n; i++) {
  31.         int numOfPayments=0;
  32.         for(; myCases[i].balence > 0; myCases[i].balence-=myCases[i].payment) {
  33.             if(numOfPayments > 1200) {
  34.                 cout<<"impossible"<<endl;
  35.                 break;
  36.             }
  37.             numOfPayments++;
  38.             myCases[i].balence+=static_cast<double>(static_cast<int>((myCases[i].balence*(myCases[i].rate/100)+0.005)*100))/100;
  39.         }
  40.         if(numOfPayments <= 1200)
  41.             cout<<numOfPayments<<endl;
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement