fork download
  1. #include<iostream>
  2. #include<cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. void test(int R , int F ,int &Num, double *&D){
  7.  
  8. double total=0;
  9. D = new double[1000];
  10. Num=0;
  11.  
  12. do{
  13. D[Num]=R+F;
  14. total+=D[Num];
  15. Num++;
  16. }while(total<=9);
  17. do{
  18. D[Num]=(R+F)/2;
  19. total+=D[Num];
  20. Num++;
  21. }while(total<=19);
  22.  
  23. for(int i=1; i<Num; i++){
  24. D[i]+=D[i-1];
  25. }
  26. cout<<"Num= "<<Num<<endl;
  27. }
  28.  
  29. int main(){
  30.  
  31. int R,F;
  32. int Num;
  33. double *D;
  34. //double *D=new double[1000];
  35. //double D[1000];
  36. cout<<"please input R & F: "<<endl;
  37. cout<<"R: ";
  38. cin>>R;
  39. cout<<"F: ";
  40. cin>>F;
  41. test(R,F,Num,D);
  42.  
  43. for(int i=0;i<Num;i++){
  44.  
  45. cout<<D[i]<<endl;
  46. }
  47.  
  48. return 0;
  49.  
  50. }
  51.  
Runtime error #stdin #stdout 0.01s 2864KB
stdin
Standard input is empty
stdout
please input R & F: 
R: