Jump to content

Programa de Registo de Clientes (problema com structs)


Recommended Posts

Posted

Boas pessoal, tenho um trabalho que consiste em fazer um programa de gestão de uma loja. Neste momento ainda estou a fazer (ou a tentar) o registo de um novo cliente. Já criei uma parte do código, mas estou com problemas quando insiro o NIF. O nome fica guardado na váriavel que criei mas o NIF apresenta um número diferente daquele que é digitado, talvez um numero que esteja guardado na memória. Se me puderem ajudar a resolver este problema, agradecia.

P.S. Inseri o código que já fiz mas o problema em si está na ultima função ("obtem_info()")

Obrigado

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100

typedef struct dados
{
    char nome[50];
    int nif;
    int n_alugueres;
} cliente;

void menuPrincipal();
void registarCliente();
cliente obtem_info();
int opcao;

int main(int argc, char** argv)
{

    printf("Bem Vindo ao Guitarras P'Alugar!!!\n");

    menuPrincipal();

    return (EXIT_SUCCESS);
}

void menuPrincipal() //falta implementar funçoes
{
    cliente loja[MAX];
    int total = 0;

    do
    {
        printf("\n\nMENU PRINCIPAL\n\n");
        printf("1 - Registar Cliente\n");
        printf("2 - Excluir Cliente\n");
        printf("3 - Listar Clientes Ativos\n");
        printf("4 - Listar Clientes Banidos\n");
        printf("5 - Sair\n\n");
        printf("Opcao: ");
        scanf("%d", &opcao);

        switch (opcao)
        {
        case 1:
            fflush(stdin);
            system("cls");
            registarCliente(loja,&total);
            break;
        case 2:
            fflush(stdin);
            system("cls");
            //excluirCliente(loja,&total);
            break;
        case 3:
            fflush(stdin);
            system("cls");
            //listarAtivos();
            break;
        case 4:
            fflush(stdin);
            system("cls");
            //listarBanidos();
            break;
        }
    }while(opcao != 5);

    printf("\nObrigado e Ate Breve!\n");
}

void registarCliente(cliente tab[], int* n)
{

    printf("Atualmente a loja possui %d clientes\n\n",*n);

    if (*n >= MAX)
    {
        printf("Loja cheia!");
    }
    else
    {
        tab[*n] = obtem_info();
        (*n)++;
    }
}

cliente obtem_info()
{
    cliente t;

    printf("Nome: ");
    scanf("%s", t.nome);

    printf("\nNIF: ");
    scanf("%d",t.nif);		//É AQUI QUE ESTÁ O PROBLEMA

    printf("Nome Introduzido: %s\n",t.nome);
    printf("NIF Introduzido: %d",&(t.nif));

    return t;
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.