BASIC Menu-driven program repeates twice after successful completion of first task.

Posted by Zazu on Stack Overflow See other posts from Stack Overflow or by Zazu
Published on 2010-05-03T19:44:12Z Indexed on 2010/05/03 19:48 UTC
Read the original article Hit count: 225

Filed under:

Hello,

Im using Plato3 to write C programs.

Im creating a menu-driven program but want to test out the basic concept of getting it to work

#include<stdio.h>
#include<ctype.h>
int function1();

main(){
  char s;
 do{
   puts("\n choose the following");
   puts("(P)rint\n");
    puts("(Q)uit\n");
   scanf("%c",&s);
   s=toupper(s);
   switch (s){
     case 'P' : function1();
        break;
        case 'Q' : return -1;
     break;
    }
 }while (function1()==0);  
}

int function1(){
   printf("Hello World");
   return 0;
 }

The problem is that once function1() returns the value 0, the whole program is echoed ... why ?

Example : Running the program gives this :

Hello WorldHellow World
 choose the following
(P)rint

(Q)uit

Hello World
 choose the following
(P)rint

(Q)uit

-- Any idea why ?

Please help, thanks !!!!

© Stack Overflow or respective owner

Related posts about c#