Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.27 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. //------------------------------------Podaj liczbe---------------
  4. double podaj_liczbe()
  5. {
  6.     double liczba;
  7.         printf("Podaj liczbe: ");
  8.         while (scanf("%lf", &liczba) == 0)
  9.         {
  10.             int ch;
  11.             while ((ch = getchar()) != '\n' && ch != EOF);
  12.             printf("Podaj liczbe: ");
  13.         }
  14.         return liczba;
  15. }
  16. //----------------------------- M A I N -----------------------------------------
  17. int main()
  18. {
  19.     double liczba = 0;
  20.     double wynik = 0;
  21.  
  22.     char wybor;
  23.     do
  24.     {
  25.         printf(" ------------------------------\n");
  26.         printf(" |                    %.6lf|\n",wynik);
  27.         printf(" ------------------------------\n");
  28.         printf(" +  p  P ) PLUS\n");
  29.         printf(" -  m  M ) MINUS\n");
  30.         printf(" *  r  R ) RAZY\n");
  31.         printf(" /  d  D ) DZIEL\n");
  32.         printf(" =  u  U ) USTAW NOWA LICZBE\n");
  33.         printf(" .  k  K ) KONIEC PROGRAMU\n");
  34.         printf(" Co chcesz zrobic ? ");
  35.  
  36. //--Wybor dzialania---------
  37.         while ((wybor = getchar()) == '\n' && wybor != EOF);
  38.      //       do
  39.  
  40.   //            wybor = getchar();
  41.     //          while (wybor == '\n');
  42.  
  43.  
  44. //----------------------------------------------------WYBOR W SWITCH'U--------------------------
  45.         switch(wybor)
  46.         {
  47.     //-------------------------------------------------D O D A W A N I E------------------------
  48.             case '+':
  49.             case 'p':
  50.             case 'P':
  51.                 liczba = podaj_liczbe();
  52.                 wynik += liczba;
  53.             break;
  54.     //------------------------------------------------O D E J M O W A N I E---------------------
  55.             case '-':
  56.             case 'm':
  57.             case 'M':
  58.                 liczba = podaj_liczbe();
  59.                 wynik -= liczba;
  60.             break;
  61.     //--------------------------------------------------M N O Z E N I E-------------------------
  62.             case '*':
  63.             case 'r':
  64.             case 'R':
  65.                 liczba = podaj_liczbe();
  66.                 wynik *= liczba;
  67.             break;
  68.     //--------------------------------------------------D Z I E L E N I E-----------------------
  69.             case '/':
  70.             case 'd':
  71.             case 'D':
  72.                 liczba = podaj_liczbe();
  73.                 while(liczba==0)
  74.                 {
  75.                     printf("Nie dzielimy przez 0 !!! \n");
  76.                     liczba = podaj_liczbe();
  77.                 }
  78.                 wynik /= liczba;
  79.             break;
  80.     //--------------------------------------------------N O W Y   W Y N I K---------------------
  81.             case '=':
  82.             case 'u':
  83.             case 'U':
  84.                     wynik = podaj_liczbe();
  85.             break;
  86.     //------------------------------------------------------K O N I E C ------------------------
  87.             case '.':
  88.             case 'k':
  89.             case 'K':
  90.                 printf("Koncze ze soba (=x_x=) Do zobaczenia ()^.^() \n");
  91.                 return 0;
  92.             break;
  93.     //---------------------------------------------------Z L E    W Y B O R Y ------------------
  94.             default:
  95.                 printf("Zly wybor.\n");
  96.  
  97.         }
  98.     }
  99.     while(wybor!='.' || wybor!='k' ||wybor!='K');
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement