Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.  
  9. int numberFishes;
  10. cin >> numberFishes;
  11.  
  12. string input;
  13. cin.ignore();
  14. getline(cin, input);
  15.  
  16. int digit = 0;
  17. int counterFishes = 0;
  18. int counter = 0;
  19.  
  20. double moneyOwned = 0;
  21. double moneySpend = 0;
  22.  
  23. while (input != "Stop" && counterFishes <= numberFishes){
  24. double kgFish;
  25. cin >> kgFish;
  26. counterFishes ++;
  27. counter ++;
  28.  
  29. cout.setf(ios::fixed);
  30. cout.precision(2);
  31.  
  32. for (int i = 0; i < input.size(); i++){
  33.     digit += input [i];
  34. }
  35.  
  36. if (counter < 3){
  37.     moneySpend += digit / kgFish * 1.0;
  38.     digit = 0;
  39. } else {
  40.     moneyOwned += digit / kgFish * 1.0;
  41.     digit = 0;
  42.     counter = 0;
  43. }
  44.  
  45. if (counterFishes == numberFishes){
  46.     break;
  47. } else {
  48. cin.ignore();
  49. getline(cin, input);
  50. }
  51. }
  52.  
  53. if (counterFishes == numberFishes){
  54.     cout << "Lyubo fulfilled the quota!" << endl;
  55. }
  56.  
  57. if (moneyOwned >= moneySpend){
  58.   cout << "Lyubo's profit from " << counterFishes << " fishes is " << moneyOwned - moneySpend << " leva." << endl;
  59. } else {
  60.     cout << "Lyubo lost " << moneySpend - moneyOwned << " leva today." << endl;
  61. }
  62.  
  63.  
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement