diff --git a/CMakeLists.txt b/CMakeLists.txt index b17af59..4d5405c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,8 @@ add_executable(skola calc.c bomba.c bomba.h do_while_znak.c - do_while_znak.h) + do_while_znak.h + for.c + for.h) target_link_libraries(skola m) diff --git a/calc.c b/calc.c index 0eb6c17..662efca 100644 --- a/calc.c +++ b/calc.c @@ -1,8 +1,17 @@ #include "stdio.h" #include "calc.h" + +//#define DOWHILE + int calc(){ char pokracovat = 'a'; + #ifndef DOWHILE while (pokracovat == 'a') { + #endif + #ifdef DOWHILE + do { + #endif + double a = 0; double b = 0; char operacia = 0; @@ -32,12 +41,14 @@ int calc(){ break; default: - printf("Nesprávna operácia.\nPrajete si pokračovať(a/n)?\n"); - scanf("%s", &pokracovat); + printf("Nesprávna operácia.\n"); } printf("Vysledok %f %c %f je: %f.\nPrajete si pokračovať(a/n)?\n", a, operacia, b, vysledok); scanf("%s", &pokracovat); } + #ifdef DOWHILE + while(pokracovat == 'a'); + #endif return 0; } \ No newline at end of file diff --git a/for.c b/for.c new file mode 100644 index 0000000..a6f945e --- /dev/null +++ b/for.c @@ -0,0 +1,17 @@ +// +// Created by bruno on 12/18/23. +// + +#include "for.h" +#include "stdio.h" + +int for_cyklus(){ + int target; + + printf("Do akého čísla počítať?"); + scanf("%d", &target); + + for(int i = 1; i <= target; i++){ + printf("%d\n", i); + } +} \ No newline at end of file diff --git a/for.h b/for.h new file mode 100644 index 0000000..89f076f --- /dev/null +++ b/for.h @@ -0,0 +1,6 @@ +// +// Created by bruno on 12/18/23. +// + + +int for_cyklus(); \ No newline at end of file diff --git a/main.c b/main.c index ffac919..857f1be 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ -#include "calc.h" +#include "for.h" int main(){ - return calc(); + return for_cyklus(); } \ No newline at end of file