Skip to content

Instantly share code, notes, and snippets.

@lucasaba
Created November 8, 2021 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasaba/42a17d960b92a26c78dfbce2d7fefb7a to your computer and use it in GitHub Desktop.
Save lucasaba/42a17d960b92a26c78dfbce2d7fefb7a to your computer and use it in GitHub Desktop.
Esercizio test
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
int main()
{
float distanza;
cout<<"Distanza in Km:";
cin >> distanza;
/**
* Calcoliamo il prezzo pieno della tratta
**/
float prezzo;
// Se distanza < 10 il prezzo è di € 1,00
if (distanza < 10) {
prezzo = 1 * distanza;
}
// Se distanza è tra 10 e 20 Km il prezzo è di € 0,70
if (distanza >= 10 && distanza < 20) {
prezzo = 0.7 * distanza;
}
// Se distanza è maggiore o uguale a 20 Km il prezzo è di € 0,50
if (distanza >= 20) {
prezzo = 0.5 * distanza;
}
/**
* Calcolo dello sconto
*/
char tipoStudente;
cout<<"Tipo studente:";
cin >> tipoStudente;
switch(tipoStudente) {
case 'a':
prezzo = (0.93 * prezzo);
cout << "Il prezzo di € " << prezzo << " è stato scontato del 7%";
break;
case 'b':
prezzo = (0.92 * prezzo);
cout << "Il prezzo di € " << prezzo << " è stato scontato del 8%";
break;
case 'c':
if (distanza > 30) {
prezzo = (0.91 * prezzo);
cout << "Il prezzo di € " << prezzo << " è stato scontato del 9%";
} else {
cout << "Il prezzo di € " << prezzo;
}
break;
default:
if (distanza > 100) {
prezzo = (0.95 * prezzo);
cout << "Il prezzo di € " << prezzo << " è stato scontato del 5%";
} else {
cout << "Il prezzo di € " << prezzo;
}
break;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment