diff --git a/exercises/ex1.cpp b/exercises/ex1.cpp index 2206958..7639181 100644 --- a/exercises/ex1.cpp +++ b/exercises/ex1.cpp @@ -1,5 +1,3 @@ -/* Improve this program using a switch-case. */ - #include using namespace std; @@ -11,38 +9,39 @@ int main() cout << "Enter week number(1-7): " << endl; cin >> week; - if (week == 1) - { - cout << "Monday" << endl; - } - else if (week == 2) - { - cout << "Tuesday" << endl; - } - else if (week == 3) - { - cout << "Wednesday" << endl; - } - else if (week == 4) - { - cout << "Thursday" << endl; - } - else if (week == 5) - { - cout << "Friday" << endl; - } - else if (week == 6) - { +switch (week) { +case 1: + cout << "Monday" << endl; + break; + +case 2: + cout << "Tuesday" << endl; + break; + +case 3: + cout << "Wednesday" << endl; + break; + +case 4: + cout << "Thursday" << endl; + break; + +case 5: + cout << "Friday" << endl; + break; + +case 6: cout << "Saturday" << endl; - } - else if (week == 7) - { + break; + +case 7: cout << "Sunday" << endl; - } - else - { - cout << "Invalid input! Please enter week number between 1-7." << endl; - } + break; + +default: + cout << "Invalid input! Please enter week number between 1-7." << endl; + break; +} return 0; } \ No newline at end of file diff --git a/exercises/sum.c b/exercises/sum.c new file mode 100644 index 0000000..98bc6fe --- /dev/null +++ b/exercises/sum.c @@ -0,0 +1,24 @@ +/* + Write a program that takes as input two numbers and print the sum. + + Output: + Insert the first number: 1 + Insert the second number: 2 + Sum: 3 +*/ + +#include +int x; +int y; +int sum; + +int main() +{ +printf("Inserisci il primo numero da sommare: "); +scanf("%d", &x); + +printf("Inserisci il secondo numero da sommare: "); +scanf("%d", &y); + +printf("La somma di %d e %d รจ %d.\n", x,y, x+y); +} \ No newline at end of file diff --git a/exercises/sum.cpp b/exercises/sum.cpp deleted file mode 100644 index 0dcca93..0000000 --- a/exercises/sum.cpp +++ /dev/null @@ -1,8 +0,0 @@ -/* - Write a program that takes as input two numbers and print the sum. - - Output: - Insert the first number: 1 - Insert the second number: 2 - Sum: 3 -*/