Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Harjoitukset 7
  5. // Tehtävä 1-4
  6. // Ilmari Ahonen
  7. // 14I220B
  8.  
  9. int nelio(int);
  10. float suorakaide(float, float);
  11. float matkanhinta(float, float, float);
  12. int palkka(int);
  13.  
  14. int main() {
  15.     int teht = 0;
  16.     while (teht != 5){
  17.         cout << "Valitse tehtava (1-4) tai lopetus (5) ";
  18.         cin >> teht;
  19.         if (cin.good() == false) {
  20.             cout << "Virheellinen syote" << endl;
  21.             break;
  22.         }
  23.         if (teht == 1) {
  24.             int i;
  25.             int tulos;
  26.             cout << "Syota luku ";
  27.             cin >> i;
  28.             tulos = nelio(i);
  29.             cout << "Luvun nelio on " << tulos << endl;
  30.             continue;
  31.         }
  32.         else if (teht == 2) {
  33.             float i1, i2;
  34.             float tulos;
  35.             cout << "Syota suorakaiteen leveys ";
  36.             cin >> i1;
  37.             cout << "Syota suorakaiteen korkeus ";
  38.             cin >> i2;
  39.             tulos = suorakaide(i1, i2);
  40.             cout << "Suorakaiteen pinta-ala on " << tulos << endl;
  41.             continue;
  42.         }
  43.         else if (teht == 3) {
  44.             float i1, i2, i3;
  45.             float tulos;
  46.             cout << "Syota ajettava kilometrimaara ";
  47.             cin >> i1;
  48.             cout << "Syota auton kulutus (l/100km) ";
  49.             cin >> i2;
  50.             cout << "Syota bensan litrahinta ";
  51.             cin >> i3;
  52.             tulos = matkanhinta(i1, i2, i3);
  53.             cout << "Matkan hinnaksi tulee " << tulos << " euroa." << endl;
  54.             continue;
  55.         }
  56.         else if (teht == 4) {
  57.             int i;
  58.             int tulos;
  59.             cout << "Syota tuntimaara ";
  60.             cin >> i;
  61.             tulos = palkka(i);
  62.             cout << "Viikon bruttopalkka on " << tulos << " euroa" << endl;
  63.             continue;
  64.         }
  65.         else if (teht == 5)
  66.             break;
  67.         else {
  68.             cout << "Virheellinen tehtava" << endl;
  69.             continue;
  70.         }
  71.     }
  72.     system("pause");
  73.     return 0;
  74. }
  75.  
  76. int nelio(int n) {
  77.     return n * n;
  78. }
  79.  
  80. float suorakaide(float s1, float s2) {
  81.     return s1 * s2;
  82. }
  83.  
  84. float matkanhinta(float h1, float h2, float h3) {
  85.     return (h1 * (h2 / 100.0f)) * h3;
  86. }
  87.  
  88. int palkka(int p) {
  89.     if (p <= 40) {
  90.         return p * 10;
  91.     }
  92.     else {
  93.         return 400 + ((p - 40) * 15);
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement