Ir ao conteúdo
  • Cadastre-se

Voltar ao menu


Posts recomendados

eae galera, sou novo aqui. fiz um programa em c e como sou novo em programação gostaria de fazer ele voltar ao menu, o programa nao esta acabado ainda, mas me ajudem com a parte do menu. abaixo esta meu codigo:

 

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
    float bit, byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, resultado;
    int materia, conversao, base,dado;
    char usuario[100];
    setlocale(LC_ALL, "Portuguese");
    printf ("DIGITE SEU NOME: ");
    scanf ("%s", &usuario);
    system ("cls");
    printf ("\n-> SEJA BEM VINDO %s <-\n\n", usuario);
    printf ("1. introdução a computação\n2. Física I\n3. Calculo I\n");
    printf ("\nDigite o número da materia: ");
    scanf ("%d", &materia);
    system ("cls");
    if (materia==1){
        printf ("\n1. Conversão de dados\n2. Conversão de bases\n");
        printf ("\nqual conversao? (1/2): ");
        scanf ("%d", &conversao);
    }
    system ("cls");
    
    switch (conversao){
    
    // CONVERSÃO DE DADOS
        case 1:
            if (dado!=7){
            printf ("tecle <enter>");
            fflush(stdin);
              while ((tecla = getchar()) != '\r')      
    
            printf ("\n<<<<<<CONVERSÃO DE DADOS>>>>>>");
            printf ("\nConverter de:\n1. bit");
            printf ("\n2. Byte");
            printf ("\n3. KiloByte");
            printf ("\n4. MegaByte");
            printf ("\n5. GigaByte");
            printf ("\n6. TeraByte");
            printf ("\n7. PetaByte");
            printf ("\n\nDigite o numero correspondente à conversão: "); // O USUARIO DIGITA O TIPO DE CONVERSAO QUE DESEJA
            scanf ("%d", &dado);
        }
        
            system ("cls");
            switch (dado){ // CADA CASE VAI SER UM CONVERSAO DIFERENTE
                case 1: // CASE DE CONVERSAO DE BIT
                    printf ("\n-> CONVERSÃO DE BIT <-\n\n");
                    printf ("Digite o valor em bit: ");
                    scanf ("%f", &bit);
                    system ("cls");
                    byte=bit/8;
                    kilobyte=byte/1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbyte: %2.2f B\n", byte);
                    printf ("kilobyte: %2.2f KB\n", kilobyte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);    
                    break;
                    
                case 2: // CASE DE CONVERSAO DE BYTE
                    printf ("\n-> CONVERSÃO DE BYTE <-\n\n");
                    printf ("Digite o valor em Byte: ");
                    scanf ("%f", &byte);
                    system ("cls");
                    bit=byte*8;
                    kilobyte=byte/1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbit: %2.2f b\n", bit);
                    printf ("kilobyte: %2.2f KB\n", kilobyte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);    
                break;
                
                case 3: //CASE DE CONVERSAO DE KILOBYTE
                    printf ("\n-> CONVERSÃO DE KILOBYTE <-\n\n");
                    printf ("Digite o valor em KiloByte: ");
                    scanf ("%f", &kilobyte);
                    system ("cls");
                    bit=kilobyte*(1024*8);
                    byte=kilobyte*1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbit: %2.2f b\n", bit);
                    printf ("kilobyte: %2.2f KB\n", byte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);    
        
                break;
                
                case 4: // CASE DE CONVERSÃO DE MEGABYTE
            
                break;
                
                case 5: // CASE DE CONVERSÃO DE GIGABYTE
                
                break;
                
                case 6: // CASE DE CONVERSÃO DE TERABYTE
            
                break;    
                
                case 7: // CASE DE CONVERSÃO DE PETABYTE
            
                break;
    
        }
        
        break; // FIM DA CONVERSAO DE DADOS
        
        //CONVERSÃO DE BASES
            case 2:
            printf ("\n<<<<<<CONVERSÃO DE BASES>>>>>>");
            printf ("\nConverter de:\n1. Binário");
            printf ("\n2. Octal");
            printf ("\n3. Decimal");
            printf ("\n4. Hexadecimal");
            printf ("\nDigite o número correspondente à transformação: ");
            scanf ("%d", &base);
            system ("cls");
        
            break;    
        
}
        return 0;
}

 

Link para o comentário
Compartilhar em outros sites

Espero ter ajudado...

#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
    float bit, byte, kilobyte, megabyte, gigabyte, terabyte, petabyte, resultado;
    int materia, conversao, base,dado, tecla;
    char usuario[100];
    bool quit_menu = false;

    setlocale(LC_ALL, "Portuguese");


    printf ("DIGITE SEU NOME: ");
    scanf ("%s", &usuario);

  	//Um loop para o menu
    //Enquanto for falso, ele vai continuar mostrando o menu
    //Ja implementei o retorno nos submenus
    //Para sair do menu, implemente uma opcao no menu abaixo
    //e um caso no switch, ai se for o numero do menu voce coloca a
    //quit_menu = true;
    while(!quit_menu){
    system ("cls");

    printf ("\n-> SEJA BEM VINDO %s <-\n\n", usuario);
    printf ("1. introdução a computação\n2. Física I\n3. Calculo I\n");
    printf ("\nDigite o número da materia: ");
    scanf ("%d", &materia);
    system ("cls");

    if (materia==1){
        printf ("\n1. Conversão de dados\n2. Conversão de bases\n");
        printf ("\nqual conversao? (1/2): ");
        scanf ("%d", &conversao);
    }
    system ("cls");

    switch (conversao){

        // CONVERSÃO DE DADOS
        case 1:
           do{
                system ("cls");
                printf ("tecle <enter>");
                fflush(stdin);
                while ((tecla = getchar()) != '\n')

                printf ("\n<<<<<<CONVERSÃO DE DADOS>>>>>>");
                printf ("\nConverter de:\n1. bit");
                printf ("\n2. Byte");
                printf ("\n3. KiloByte");
                printf ("\n4. MegaByte");
                printf ("\n5. GigaByte");
                printf ("\n6. TeraByte");
                printf ("\n7. PetaByte");
                printf ("\n8. Retornar ao menu");
                printf ("\n\nDigite o numero correspondente à conversão: "); // O USUARIO DIGITA O TIPO DE CONVERSAO QUE DESEJA
                scanf ("%d", &dado);
                //Voltar ao menu
                if(dado == 8) break;

            }while(dado<1 && dado >7);

            switch (dado){ // CADA CASE VAI SER UM CONVERSAO DIFERENTE
                case 1: // CASE DE CONVERSAO DE BIT
                    printf ("\n-> CONVERSÃO DE BIT <-\n\n");
                    printf ("Digite o valor em bit: ");
                    scanf ("%f", &bit);
                    system ("cls");
                    byte=bit/8;
                    kilobyte=byte/1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbyte: %2.2f B\n", byte);
                    printf ("kilobyte: %2.2f KB\n", kilobyte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);
                    break;

                case 2: // CASE DE CONVERSAO DE BYTE
                    printf ("\n-> CONVERSÃO DE BYTE <-\n\n");
                    printf ("Digite o valor em Byte: ");
                    scanf ("%f", &byte);
                    system ("cls");
                    bit=byte*8;
                    kilobyte=byte/1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbit: %2.2f b\n", bit);
                    printf ("kilobyte: %2.2f KB\n", kilobyte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);
                break;

                case 3: //CASE DE CONVERSAO DE KILOBYTE
                    printf ("\n-> CONVERSÃO DE KILOBYTE <-\n\n");
                    printf ("Digite o valor em KiloByte: ");
                    scanf ("%f", &kilobyte);
                    system ("cls");
                    bit=kilobyte*(1024*8);
                    byte=kilobyte*1024;
                    megabyte=kilobyte/1024;
                    gigabyte=megabyte/1024;
                    terabyte=gigabyte/1024;
                    petabyte=terabyte/1024;
                    printf ("\nbit: %2.2f b\n", bit);
                    printf ("kilobyte: %2.2f KB\n", byte);
                    printf ("megabyte: %2.2f MB\n", megabyte);
                    printf ("gigabyte: %2.2f GB\n", gigabyte);
                    printf ("terabyte: %2.2f TB\n", terabyte);
                    printf ("petabyte: %2.2f PB\n", petabyte);
                break;

                case 4: // CASE DE CONVERSÃO DE MEGABYTE

                break;

                case 5: // CASE DE CONVERSÃO DE GIGABYTE

                break;

                case 6: // CASE DE CONVERSÃO DE TERABYTE

                break;

                case 7: // CASE DE CONVERSÃO DE PETABYTE

                break;

            }
        break; // FIM DA CONVERSAO DE DADOS

        //CONVERSÃO DE BASES
            case 2:
            do
            {
                system ("cls");
                printf ("tecle <enter>");
                fflush(stdin);
                while ((tecla = getchar()) != '\n')

                printf ("\n\n<<<<<<CONVERSÃO DE BASES>>>>>>");
                printf ("\nConverter de:\n1. Binário");
                printf ("\n2. Octal");
                printf ("\n3. Decimal");
                printf ("\n4. Hexadecimal");
                printf ("\n5. Retornar ao menu");
                printf ("\nDigite o número correspondente à transformação: ");
                scanf ("%d", &base);
                system ("cls");
                //Voltar ao menu
                if(base == 5) break;

            }while(base <0 || base > 4);
            switch(base){
                default:
                break;
            }
            break;
            default:
            break;
        }
    }
return 0;
}

 

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

Ebook grátis: Aprenda a ler resistores e capacitores!

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!