Build error: expected ';' before 'case'

Asked

Viewed 115 times

1

I’m trying to compile this program here in Code::Blocks but I’m not getting it and I don’t understand why.

#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using std::endl;
using std::cout;
using std::cin;
int main()
 
{
    int x = 0;
    cout << "Qual o mês atual Digite apenas um número de 0 a 12" <<  endl;
    cin >> x ;
    switch (x)
 {
     case 1 : cout << "Janeiro" << endl; break
     case 2 : cout << "Fevereiro" << endl; break
     case 3 : cout << "Março" << endl; break
     case 4 : cout << "Abril" << endl; break
     case 5 : cout << "Maio" << endl; break
     case 6 : cout << "Junho" << endl; break
     case 7 : cout << "Julho" << endl; break
     case 8 : cout << "Agosto" << endl; break
     case 9 : cout << "Setembro" << endl; break
     case 10 : cout << "Outubro" << endl; break
     case 11 : cout << "Novembro" << endl; break
     case 12 : cout << "Dezembro" << endl; break
     default : cout << "Digite um número de 0 à 12" << endl;
     }
 
 
}

Código.

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

4

The compiler showed what the error is, just read it and fix it. Missing the ; after each break to close the statement. Maybe if you hadn’t put it all on the same line that would have made it clearer.

I gave a better organized code. More readable codes are easier to find errors.

#include <iostream>
using namespace std;

int main() {
    int x = 0;
    cout << "Qual o mês atual Digite apenas um número de 0 a 12" << endl;
    cin >> x ;
    switch (x) {
        case 1 : cout << "Janeiro" << endl; break;
        case 2 : cout << "Fevereiro" << endl; break;
        case 3 : cout << "Março" << endl; break;
        case 4 : cout << "Abril" << endl; break;
        case 5 : cout << "Maio" << endl; break;
        case 6 : cout << "Junho" << endl; break;
        case 7 : cout << "Julho" << endl; break;
        case 8 : cout << "Agosto" << endl; break;
        case 9 : cout << "Setembro" << endl; break;
        case 10 : cout << "Outubro" << endl; break;
        case 11 : cout << "Novembro" << endl; break;
        case 12 : cout << "Dezembro" << endl; break;
        default : cout << "Digite um número de 0 à 12" << endl;
     }
 }

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • It worked, thank you.

  • Mate, if the answer helped you, please consider mark her as accepted. In addition to helping the system work better, this is the most appropriate way to thank those who helped you. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.