#include <iostream>
#include <string>
using namespace std;
//void multiply(int b);
int main()
{
float total = 0;
float b = 0;
cout << "Enter number: " << endl;
cin >> b;
char TorD;
cout << "Would you like to times (*), divide (/), add (+) or minus (-) this number?" << endl;
cin >> TorD;
switch (TorD)
case '*' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b * c;
cout << b << " * " << c << " = " << total << endl;
}
break;
case '/' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b/c;
cout << b << "/" << c << " = " << total << endl;
}
break;
case '+' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b + c;
cout << b << " + " << c << " = " << total << endl;
}
break;
case '-' :
{
int c=0;
cout << "by how many?" << endl;
cin >> c;
total = b - c;
cout << b << " - " << c << " = " << total << endl;
}
break;
default:
cout << "You did not correctly enter /, *, +, or - !!" << endl;
//multiply(b);
system("pause");
return 0;
}
0
A
Répondre
8
vous manque l'accolade ouverte après la switch (TorD)
, de sorte que la « rupture » est en dehors de toute déclaration à rompre (à savoir une rupture a pour être à l'intérieur d'une boucle ou d'un commutateur de sorte qu'il a quelque chose à sortir de). L'instruction switch devrait ressembler à:
switch (TorD) {
case '*': {
// ...
}
break;
case '/': {
// ...
}
break;
// ...and so on.
}
0
Vous avez oublié les accolades autour des déclarations de cas après la mise.
2
Vous devez accolades pour votre commutateur:
switch (...)
{ // your forgot this
...
} // and this
A une supposition, la mise en correspondance accolade fermante doit aller au-dessus du '// multiplier (b)' commentaire. –