Hello all,
Below is my first program in C using 'IF and ELSE' along with 'DO...WHILE' loop in between.
My program is pretty simple and I understand I could accomplish what I'm trying to do here by only using 'WHILE' loop. However; for understanding and experimenting purposes I would like to have my program run as below.
It throws an error when I try compiling. Can someone please help in rectifying errors in the below code?
Code:#include <stdio.h> int main() ( int a; printf( "What is 2 + 2? "); scanf ( "%d", &a ); if ( a == 4 ) { printf( "You are correct!\n" ); } else { do { printf ( "You are incorrect.\n" ); printf ( "Please try again: " ); scanf ( "%d", &a ); }while( a == 4 ); printf( "You are correct!\n" ); getchar(); return 0; } )