BASIC Menu-driven program repeates twice after successful completion of first task.
- by Zazu
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 !!!!