MegaTor

Norske We Charge-priser (Ionity)

Sep 14th, 2020 (edited)
692
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. #include "colors.h"
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. bool runAgain = true;
  9.  
  10. string s_line, s_consumption, s_km, s_kWh;
  11.  
  12. int i_km, i_mil;
  13. double d_consumption, d_kWh, d_price, d_dropIn, d_weChargeGo, d_weChargePlus;
  14.  
  15. void run();
  16.  
  17. void init()
  18. {
  19.     // Intialiser alle variabler til standard
  20.     s_line = s_consumption = s_km = s_kWh = "0";
  21.     d_consumption = d_kWh = d_price = d_dropIn = d_weChargeGo = d_weChargePlus = 0.0f;
  22.     i_km = i_mil = 0;
  23. }
  24.  
  25. void runOverAgain()
  26. {
  27.     cout << cflYELLOW << "Vil du fortsette? Skriv inn J for ja eller N for nei og trykk Enter: " << cflGREEN_;
  28.     getline(cin, s_line);
  29.     cout << cdefault_;
  30.  
  31.     if (s_line == "J" || s_line == "j")
  32.     {
  33.         init();
  34.         run();
  35.     }
  36.  
  37.     else if (s_line == "N" || s_line == "n")
  38.     {
  39.         runAgain = false;
  40.     }
  41.  
  42.     else
  43.     {
  44.         system("cls");
  45.         runOverAgain();
  46.     }
  47. }
  48.  
  49. void run()
  50. {
  51.     system("cls");
  52.     cout << "Kun heltall er tillatt for antall km du kj\x9brer i \x86ret.\n\n";
  53.  
  54.     cout << "Skriv inn antatt forbruk i antall kWh per mil (10 km).\nBruk punktum som komma. H\x9byeste tillatte tall er 5 og laveste tillatte tall er 1.\n";
  55.     cout << cflYELLOW << "Antall kWh per mil: " << cflGREEN_;
  56.     getline(cin, s_consumption);
  57.     d_consumption = atof(s_consumption.c_str());
  58.  
  59.     while (d_consumption > 5 || d_consumption < 1)
  60.     {
  61.         cout << cflYELLOW << "Antall kWh per mil: " << cflGREEN_;
  62.         getline(cin, s_consumption);
  63.         d_consumption = atof(s_consumption.c_str());
  64.     }
  65.     cout << cdefault_;
  66.  
  67.     cout << "\nSkriv inn antall kilometer du kj\x9brer per \x86r uten mellomrom og kun heltall.\n" << cflYELLOW << "Du kan skrive inn opptil 100000 (minimum 10): " << cflGREEN_;
  68.     getline(cin, s_km);
  69.     i_km = atoi(s_km.c_str());
  70.  
  71.     while (i_km > 100000 || i_km < 10)
  72.     {
  73.         cout << cflYELLOW << "Antall km per \x86r: " << cflGREEN_;
  74.         getline(cin, s_km);
  75.         i_km = atoi(s_km.c_str());
  76.     }
  77.     cout << cdefault_;
  78.  
  79.     i_mil = i_km / 10;
  80.     // Konverter til antall kWh som trengs
  81.     d_kWh = i_mil * d_consumption;
  82.  
  83.     // Regn ut prisen for hver av abonnementene og drop-in hos Ionity
  84.     d_dropIn = 8.4 * d_kWh;
  85.     d_weChargeGo = ((double)12 * 79) + (d_kWh * 4.4);
  86.     d_weChargePlus = ((double)12 * 189) + (d_kWh * 1.6);
  87.  
  88.  
  89.     // Skriv ut hvert av totalbeløpene og antall kroner per mil
  90.     cout << cflGREEN_ << "\n\nPrisen ved \x86 lade med kun drop-in blir kr. " << d_dropIn << " eller kr. " << fixed << setprecision(2) << d_dropIn / i_mil << " / mil\n";
  91.  
  92.     cout << cflGREEN_ << "\nPrisen ved \x86 lade med We Charge Go blir kr. " << d_weChargeGo << " eller kr. " << fixed << setprecision(2) << d_weChargeGo / i_mil << " / mil\n";
  93.  
  94.     cout << cflGREEN_ << "\nPrisen ved \x86 lade med We Charge Plus blir kr. " << d_weChargePlus << " eller kr. " << fixed << setprecision(2) << d_weChargePlus / i_mil << " / mil\n\n\n" << cdefault_;
  95.  
  96.     runOverAgain();
  97. }
  98.  
  99.  
  100. int main()
  101. {
  102.     init();
  103.  
  104.     while (runAgain)
  105.     {
  106.         run();
  107.     }
  108.  
  109.     return 0;
  110. }
RAW Paste Data