Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <iostream> /* File: construction-destruction-order.cpp */
  2. using namespace std;
  3.  
  4.  
  5. int main(){
  6. int k=0;
  7. int max=0;
  8. int min=0;
  9. double sum=0;
  10. int temp=0;
  11. int ntemp=0;
  12. bool changed= false;
  13. do{
  14. cout<<"please input a number k"<<endl;
  15. cin>>k;
  16. }while(k<=0);
  17. cout<<"the number of positive integers is "<<k<<endl;
  18. cout<<"please input "<<k<<" strictly increasing positive integers"<<endl;
  19. int i=k;
  20. while(i>0){
  21. cin>>ntemp;
  22. if(ntemp<0){
  23. while(i-1>0){
  24. cin>>ntemp;
  25. i--;
  26. }
  27. cout<<"please input the positive integers"<<endl;
  28. return 0;
  29. }
  30. if(ntemp<temp){
  31. cout<<"please input strictly increasing positive integers"<<endl;
  32. cout<<"please input: "<<endl;
  33. cin>>ntemp;
  34. while(ntemp<temp){
  35. cout<<"please input again:"<<endl;
  36. cout<<"please input: "<<endl;
  37. cin>>ntemp;
  38. }
  39. changed = true;
  40. }
  41. temp=ntemp;
  42. if(temp>max||i==k){
  43. max=temp;
  44. }
  45. if(temp<min||i==k){
  46. min=temp;
  47. }
  48. sum+=temp;
  49. i--;
  50. }
  51. double avg = sum/k;
  52. if(changed){
  53. cout<<"after changing, input increasing ok"<<endl;
  54. }
  55. else{
  56. cout<<"total input increasing ok"<<endl;
  57. }
  58. cout<<"min: "<<min<<" max:"<<max<<" average: "<<avg<<endl;
  59. return 0;
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement