program people registration error line 70 expected while before '}' token

help me please this people registration program is giving this error what do i do? error line 70 expected while before '}' token

#include <iostream>
#include <cmath>
#include <cstring>
#include <string.h>
#define LIMITE 200
using namespace std;

char nome [LIMITE] [50]; //definiu variaveis o tamanho e o tamanho da linha 50
char email[LIMITE] [50];
int cpf [LIMITE];
int opcao;
void cadastro();
void pesquisa();
int main (void){
cadastro();
pesquisa();
}
void cadastro() {
static int linha;
do{
cout << "\nDigite o nome: ";
cin >> nome[linha];
cout << "\nDigite o email: ";
cin >> email[linha];
cout << "\nDigite o cpf: ";
cin >> cpf[linha];
cout << "\nDigite 1 para continuar ou outro valor para sair ! ";
cin >> opcao;
linha++;

}while(opcao ==1); //executado pelo menos uma vez
}
//fim da função cadastro
void pesquisa(){ //cria uma função para pesquisa
int cpfPesquisa;
char emailPesquisa[50];
int i;
do{
cout <<"\nDigite 1 para pesquisar o CPF ou 2 para pesquisar o email";
cin >> opcao;
switch(opcao){
case 1 :
cout <<"\nDigite o CPF para a pesquisa: ";
cin >> cpfPesquisa;
for(i =0; i< LIMITE; i++){
if(cpf[i] == cpfPesquisa){
cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];
}
} //cadastra todos os CPF no programa

break;
case 2 :
cout << "\nDigite o email para a pesquisa:";
cin >> emailPesquisa;
for(i =0; i< LIMITE; i++)
{
if(strcmp(email[i] , emailPesquisa)){ //compara se o vetor i é igual a variavel emailpesquisa
cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];
}
break;
default:
cout <<"\nOpção inválida !";
break;
}
cout << "\nDigite 1 para continuar pesquisando ";
cin >> opcao;
} while(opcao == 1);
}
}
its probably a screwed up bracket. which we can't see because you didn't use code tags to give us a sane indentation guide. Use the <> on the side editor to add code tags. Put every matched pair of brackets in the same columns and see if you spot something wrong, or if your IDE supports it, do matching braces around the problem to see which bracket goes to what and correct it.
Last edited on
Also, you can't just make up how the language works:

 
cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];

If you format your code properly you can easily see that the for loop is missing the closing curly brace.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <cmath>
#include <cstring>
#include <string.h>
#define LIMITE 200
using namespace std;

char nome [LIMITE] [50]; //definiu variaveis o tamanho e o tamanho da linha 50
char email[LIMITE] [50];
int cpf [LIMITE];
int opcao;

void cadastro();
void pesquisa();

int main (void)
{
  cadastro();
  pesquisa();
}
void cadastro()
{
  static int linha;
  do
  {
    cout << "\nDigite o nome: ";
    cin >> nome[linha];
    cout << "\nDigite o email: ";
    cin >> email[linha];
    cout << "\nDigite o cpf: ";
    cin >> cpf[linha];
    cout << "\nDigite 1 para continuar ou outro valor para sair ! ";
    cin >> opcao;
    linha++;

  }
  while(opcao ==1);   //executado pelo menos uma vez
}
//fim da função cadastro
void pesquisa()  //cria uma função para pesquisa
{
  int cpfPesquisa;
  char emailPesquisa[50];
  int i;
  do
  {
    cout <<"\nDigite 1 para pesquisar o CPF ou 2 para pesquisar o email";
    cin >> opcao;
    switch(opcao)
    {
      case 1 :
        cout <<"\nDigite o CPF para a pesquisa: ";
        cin >> cpfPesquisa;
        for(i =0; i< LIMITE; i++)
        {
          if(cpf[i] == cpfPesquisa)
          {
            cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];
          }
        } //cadastra todos os CPF no programa

        break;
      case 2 :
        cout << "\nDigite o email para a pesquisa:";
        cin >> emailPesquisa;
        for(i =0; i< LIMITE; i++)
        {
          if(strcmp(email[i], emailPesquisa))   //compara se o vetor i é igual a variavel emailpesquisa
          {
            cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];
          }
          break;
      default:
        cout <<"\nOpção inválida !";
        break;
      }
      cout << "\nDigite 1 para continuar pesquisando ";
      cin >> opcao;
    }
    while(opcao == 1);
  }
}
cout <<"\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i];
This doesn't do what you think it does. It's one of the pitfalls of C++: sometimes a things that seem right to a beginner will compile, but do something completely different.

What you want is:
cout << "\n Nome: %s\nEmail: %s\nCPF : %d" << nome[i] << email[i] << cpf[i];

Edit: See Gando's post below.

If you're curious, what you wrote is basically the same as:
1
2
3
4
cout <<"\n Nome: %s\nEmail: %s\nCPF : %d";
nome[i];  // evaluate this expression and throw away the result
email[i]; // ditto
cpf[i];   // ditto 


In the expression a,b the program evaluates a, throws away the result, then evaluates b. This is value of the entire expression. I rarely use it, but it can be handy in statements like:
1
2
3
while (cout >> "Enter a number: ", cin >> num) {
   ...
}

Edit: See doug4's post below.

cout >> "Enter a number: " prompts for a number. The program then executes cin >> num and the result (whether cin is still good) is the value of the test expression for the while loop.
Last edited on
What you want is:
cout << "\n Nome: %s\nEmail: %s\nCPF : %d" << nome[i] << email[i] << cpf[i];
I mean, that still isn't right :) couts don't work with printf syntax (as I'm sure you know, just pointing it out for the OP).

Either
printf("\n Nome: %s\nEmail: %s\nCPF : %d", nome[i], email[i], cpf[i]);
or
cout << "\n Nome: " << nome[i] << "\nEmail: " << email[i] << "\nCPF: " << cpf[i];
Last edited on
Another typo in your example:

while (cout >> "Enter a number: ", cin >> num)

Should be:
while (cout << "Enter a number: ", cin >> num)
SMH.

Then SMH again. :)

Thanks for the corrections gando and Doug4.
Yeah, you should be more frickin’ careful in future Grandpa hayden.
Topic archived. No new replies allowed.