Krat0s
31-08-2009, 14:28
'giorno a tutti....
ho trovato dei problemi per implementare un mini-programma che, dati due numeri e il segno, da la soluzione. So che č semplice ma ho un problema con l'uso di switch. Ecco il codice:
#include <iostream>
using namespace std;
int main ()
{
float a,b,temp;
char segno;
cout << "Inserire i due numeri: ";
cin >> a >> b;
cout << "Inserire il segno: ";
cin >> segno;
switch (segno) {
case +:
temp = a+b;
cout << "Num. 1 + Num.2 = " << temp;
break;
case -:
temp = a-b;
cout << "Num. 1 - Num.2 = " << temp;
break;
case *:
temp = a*b;
cout << "Num. 1 * Num.2 = " << temp;
break;
case /:
temp = a/b;
cout << "Num. 1 / Num.2 = " << temp;
break;
}
system("Pause");
return 0;
}
Mi vengono dati i seguenti errori:
Compiling: C:\Documents and Settings\Kratos\Desktop\Untitled1.c
C:\Documents and Settings\Kratos\Desktop\Untitled1.c: In function `int main()':
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:13: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:17: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:21: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:21: error: `*' cannot appear in a constant-expression
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:25: error: expected primary-expression before '/' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:25: error: expected primary-expression before ':' token
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 0 warnings
Qualcuno puņ dirmi dove sbaglio? grazie
ho trovato dei problemi per implementare un mini-programma che, dati due numeri e il segno, da la soluzione. So che č semplice ma ho un problema con l'uso di switch. Ecco il codice:
#include <iostream>
using namespace std;
int main ()
{
float a,b,temp;
char segno;
cout << "Inserire i due numeri: ";
cin >> a >> b;
cout << "Inserire il segno: ";
cin >> segno;
switch (segno) {
case +:
temp = a+b;
cout << "Num. 1 + Num.2 = " << temp;
break;
case -:
temp = a-b;
cout << "Num. 1 - Num.2 = " << temp;
break;
case *:
temp = a*b;
cout << "Num. 1 * Num.2 = " << temp;
break;
case /:
temp = a/b;
cout << "Num. 1 / Num.2 = " << temp;
break;
}
system("Pause");
return 0;
}
Mi vengono dati i seguenti errori:
Compiling: C:\Documents and Settings\Kratos\Desktop\Untitled1.c
C:\Documents and Settings\Kratos\Desktop\Untitled1.c: In function `int main()':
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:13: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:17: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:21: error: expected primary-expression before ':' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:21: error: `*' cannot appear in a constant-expression
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:25: error: expected primary-expression before '/' token
C:\Documents and Settings\Kratos\Desktop\Untitled1.c:25: error: expected primary-expression before ':' token
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 0 warnings
Qualcuno puņ dirmi dove sbaglio? grazie