Repeat Function

I'm making user defined function which will repeat when i will press any key except 'a' it will print 'Hey'. and when 'a' is pressed it will print 'bye'.
but having some troubles please correct the code it shows error that declaration terminated incorrectly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<stdio.h>
#include<conio.h>

void rep();
void main()
{
clrscr();
rep();
getch();
}

void rep()
{ printf("Hey\n");  }
{ getch!='a'; rep(); }
 else
 printf("bye");
Hi,

==>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<conio.h>

 void rep();
 int main()
 {
     clrscr();

     printf("Hey! Please press 'a' to exit...\n");
     rep();
     getch();
 }

 void rep()
 {
     printf("Hey\n");  
     if(getch() != 'a') rep(); 
     printf("bye"); return;
 }
Last edited on
Does that help you? :)
it gives new error
"cannot covert char into int"
I edited my solution. Go ahead and compile it.

And let us know your output outcome :)
thank you it worked :-) thank you soo much :)
Glad it helped :)
Topic archived. No new replies allowed.