Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    102

    Problema con while(1)

    Quando eseguo il programma tutto ok, ma una volta uscito dallo switch mi viene chiesto due volte di seguito "Inserire il voto dello studente". Perchè ? Problema del while(1) ?
    codice:
    #include <stdio.h>
    int main()
    {
    	char a;
    	while(1)
    	{
    		printf("Inserire il voto dello studente: ");
    		scanf("%c",&a);
    		switch(a)
    		{
    			case '\n':
    			case '\t':
    			case ' ':
    				continue;
    			case 'a':
    				printf("AMMESSO\n");
    				break;
    			case 'b':
    				printf("BOCCIATO\n");
    				break;
    			case 's':
    				printf("SOSPENSIONE GIUDIZIO\n");
    				break;
    			default:
    				printf("Carattere non valido\n");
    				break;
    		}
    	}	
    }

  2. #2
    Tu quanti caratteri inserisci esattamente?


    codice:
    scanf( "%c%*c", &a );

    Fracty - The Fractal Generator



    If you cannot choose a concise name that expresses what the method does, it is possible that your method is attempting to perform too many diverse tasks.

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    102
    [QUOTE]Originariamente inviato da GliderKite

    Funziona
    Scusami, ma è un puntatore quello ? In cosa consiste un comando simile ?

  4. #4
    Leggi qua
    Fracty - The Fractal Generator



    If you cannot choose a concise name that expresses what the method does, it is possible that your method is attempting to perform too many diverse tasks.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.