18/12/2018, 00:38
1 #include <iostream>
2 #include <cmath>
3 using namespace std;
4
5 constexpr double taux_change;
6 constexpr int nb_essais;
7 taux_change = 1.18;
8 nb_essais = 5;
9
10 bool egaux(double x, double y, double precision = 1e-2)
11 {
12 return abs(x - y) < precision;
13 }
14
15 int main()
16 {
17 int x;
18 cout << "Qual'è il valore di 1 euro in franchi svizzeri ?" << endl;
19 bool trouve;
20 for (int i(1); trouve or (i < nb_essais); ++i) ;
21 {
22 cout << "Tentativo no" << i << " : ";
23 cin >> x;
24 trouve = egaux(x, taux_change);
25 }
26 if (i > 10)
27 cout << "Perso. :-(" << endl;
28 else
29 cout << "Bravo ! :-)" << endl;
30
31 return 0;
32 }
10 bool egaux(double x, double y, double precision = 1e-2)
11 {
12 return abs(x - y) < precision;
13 }
10 bool egaux(double x, double y, double precision = 1e-2)
11 {
12 if(abs(x - y) < precision){
13 return true;
14 }else{
15 return false;
16 } }
19 bool trouve(false);
20 for (int i(1); not(trouve or (i <= nb_essais)); ++i)
21 {
26 if (trouve == false)
27 cout << "Perso. :-(" << endl;
28 else
29 cout << "Bravo ! :-)" << endl;
30
31 return 0;
32 }
18/12/2018, 08:35
non sono sicuro si possano inizializzare variabili constexpr in quel modo
Errore 1:
La funzione dovrebbe ritornare un booleano mentre lì ritorna un espressione.
Concezione sbagliata di condizione d'arresto del ciclo for, infatti il ciclo deve terminare se ha trovato il giusto tasso di cambio oppure se il numero di tentativi è superiore (strettamente) a 5
...
- Codice:
for (int i(1); not(trouve or (i <= nb_essais)); ++i)
not(trouve) and not(i <= nb_essais)
19/12/2018, 22:53
19/12/2018, 23:32
Raptorista ha scritto:Non dimenticare gli errori alla riga 18: Qual è, senza apostrofo.
Skuola.net News è una testata giornalistica iscritta al Registro degli Operatori della Comunicazione.
Registrazione: n° 20792 del 23/12/2010.
©2000—
Skuola Network s.r.l. Tutti i diritti riservati. — P.I. 10404470014.
Powered by phpBB © phpBB Group - Privacy policy - Cookie privacy
phpBB Mobile / SEO by Artodia.