I don’t know what’s wrong with my show

Asked

Viewed 52 times

-1

In the exercise I need to create a struct for the registration of an address book, names, age and phones of five people, and define the appropriate registration structure, block diagram and encodings of a program that perform the following tasks:

a- registration of information: name, address, age and telephone number.

b- the age survey.

c- classification in alphabetical order

d- modification of any record that has been provided with error.

and- get out

The program must have an options menu, so that the user selects the desired option regardless of a specific order.

Follow below my program

#include <stdio. h> #include <conium. h> #include <string. h>

int main(){

int i, pesq[90], flag, b[90], j, op, re; char Resp=’s';

struct cad_agenda {
int tel, id; char nome[90], Ende[130]; }; struct cad_agenda a[5];

 while(resp=='s' || resp=='S'){
 
 printf("\nPROGRAMA AGENDA\n");
 printf("1-Cadastro e registros\n");
 printf("2-Pesquisa de resgistros\n");
 printf("3-Classificação alfabética\n");
 printf("4-Alteração de registro\n");
 printf("5-Sair\n");
 
 printf("Escolha uma opcao:");
 scanf("%d", &op);  
 printf("\n");
 
 switch(op){
 
 case 1: 
 
 for(i=0; i<=4; i++){
  printf("Digite o nome:\n");
 fgets(a[i].nome,90,stdin);
 
 printf("Digite o endereço:\n");
 fgets(a[i].ende,130,stdin);
 
 printf("Digite a idade:\n");
 scanf("%d", &a[i].id);
 
 printf("Digite o telefone:\n");
 scanf("%d", &a[i].tel);        
 }break;

 case 2: 
 printf("Digite a idade para pesquisar:");
 scanf("%d", &a[i].id);
 
 i=0;
 flag=0;
 
 while(i<=4 && flag==0){
 
 if(strcmp(a[i].id, pesq)==0)
 flag=1;
 
 else
 i+=1;
 }
 
 if(flag==1){
 printf("A idade foi localizada na posicao: %d\n", i);
 else
 printf("A idade não foi localizada!\n");   
 }
 }
 case 3:
 for(i=0; i<=3; i++){
 for(b=i+1; b<=4; b=b+1){
    
 if(strcmp(a[i].nome, a[b].nome)>0){
 
 strcpy(j, a[i].nome);
 strcpy(a[i].nome, a[b].nome);
 strcpy(a[b].nome, j);  
 }  
 }  
 for(i=0; i<=4; i=i+1)
 puts(a[i].nome);
 }break;

 case 4:
 printf("Digite o campo que deseja alterar:");
 fgets(pesq,5,stdin);
 
 i=0;
 flag=0;
 
 while(i<=4; && flag==0){
 
 if(strcmp(a[i].nome, pesq)==0)
 flag=1;
 
 else
 i+=1;  
 }
 
 if(flag==1){
 printf("O nome foi localizado na posicao: %d\n",i);    
 
 printf("2-Nome\n");
 printf("3-Idade\n");
 printf("4-Endereco\n");
 printf("5-Sair\n");
 
 printf("Escolha uma opcao:");
 scanf("%d", &re);
 
 switch(re){
    
 case 2: 
 printf("Digite o novo telefone: %d\n");
 scanf("%d", &a[i].nome);
 printf("O nome foi alterado!"); break;
 
 case 3:
 printf("Digite a nova idade: %d\n");
 scanf("%d", &a[i].id);
 printf("O nome foi alterado!"); break;
 
 case 4:
 printf("Digite o novo endereço!");
 scanf("%d", &a[i].ende);
 printf("O novo endereco foi alterado!"); break
 
 case 5:
 printf("Deseja continuar? [S]IM/ [N]AO + <enter>");
 fflush(stdin); resp=getchar(); 
    
 default:
 printf("Campo nao encontrado!"); break
 }
}

} getch(); Return 0; }

  • The code is very complex and difficult to understand, besides some problems that prevent it from being compiled. Try to organize it into functions, this helps a lot. Also, structures should be declared outside the main.

1 answer

1

while(Resp==’s' || Resp==’S'){

its condition is wrong. the while and a repeat structure in which case it will repeat endlessly

as described in it until Resp is different from s

Browser other questions tagged

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