mathiaspl20

Untitled

Nov 5th, 2019
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. unsigned long ResistorColor(unsigned long resistance);
  5.  
  6. int main()
  7. {
  8. std::cout << "Geben sie einen Wiederstandswert zwischen 1Ω und 5MΩ dessen Farbcode sie wissen möchten ein: ";
  9. unsigned long x;
  10. std::cin >> x;
  11. if (!std::cin)
  12. {
  13. std::cout << "Das war keine ganze Zahl! Bitte geben sie eine ganze Zahl ein: ";
  14. }
  15. while (!std::cin) {
  16. std::cin.clear();
  17. std::cin.ignore();
  18. std::cin >> x;
  19. }
  20.  
  21. ResistorColor(x);
  22. }
  23.  
  24. unsigned long ResistorColor(unsigned long resistance)
  25. {
  26. unsigned long tmp = resistance;
  27. std::string code;
  28. while (tmp >= 10)
  29. {
  30. tmp = tmp / 10;
  31. }
  32.  
  33. switch (tmp) {
  34. case 0: code.append("schwarz ");
  35. case 1: code.append("braun ");
  36. case 2: code.append("rot ");
  37. case 3: code.append("orange ");
  38. case 4: code.append("gelb ");
  39. case 5: code.append("grün ");
  40. case 6: code.append("blau ");
  41. case 7: code.append("violett ");
  42. case 8: code.append("grau ");
  43. case 9: code.append("weiss ");
  44. default: code = "error";
  45. }
  46. }
  47. return code;
  48. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×