You are here:   HomeC Programming (Theory)Control Structures in CWrite a C program to illustrate the concept of break statement.
by Dinesh Thakur Category: Control Structures

 

 

#include<stdio.h>

#include<conio.h>
void main()
{
long luckyNumber=15;
int yourInput =0;
int count=3;
for(;count>0;--count)
{
printf("\n You have %d tr%s left.",count,count==1?"y":"ies");
printf("\nEnter:");
scanf(“%d",&yourInput);
if(yourlnput==luckyNumber)
{
printf("\nYou guessed it!\n");
return;
}
if(yourlnput<1 || yourInput>20)
printf("I said between 1 and 20.\n");
else
printf("Sorry. %d is wrong.\n",yourlnput);
}
printf("\nYou have had three tries and failed. The number was %ld\n",1uckyNumber);
getch();
}
 
OUTPUT:
 
You have 3 tries left,
Enter: 3
Sorry. 3 is wrong.
You have 2 tries left,
Enter: 15
You guessed it!
 


Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.



What's New and Popular





Popular Article