Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com How to stop the loop when user enter negative number?
 User Name Remember Me? Password

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 12-21-2011, 07:13 AM PM User | #1 calestia New to the CF scene   Join Date: Dec 2011 Posts: 1 Thanks: 1 Thanked 0 Times in 0 Posts How to stop the loop when user enter negative number? here's the question : Write a program that reads a positive -digit integer and prints the word equivalent for it. For example if the user enter 6, your program should print You have entered six. The program should execute repeatedly until the user enters a negative digit. Use user defined function in this program. and this is my coding : #include void digit(int); void main(){ int number,i=0; while ( i==0 ){ printf("Enter positive number in range [1-9]: "); scanf("%d", &number); if (number >= 0 && number <=9) digit(number); else if ( !(number >= 0 && number <=9) ) printf("Sorry invalid number: Try again\n"); } } void digit(int number){ if (number == 1) printf("\nYou entered the number One\n"); else if (number == 2) printf("\nYou entered the number Two\n"); else if (number == 3) printf("\nYou entered the number Three\n"); else if (number == 4) printf("\nYou entered the number Four\n"); else if (number == 5) printf("\nYou entered the number Five\n"); else if (number == 6) printf("\nYou entered the number Six\n"); else if (number == 7) printf("\nYou entered the number Seven\n"); else if (number == 8) printf("\nYou entered the number Eight\n"); else if (number == 9) printf("\nYou entered the number Nine\n");
12-21-2011, 07:45 AM   PM User | #2
abduraooft
Supreme Master coder!

Join Date: Mar 2007
Location: N/A
Posts: 14,779
Thanks: 159
Thanked 2,213 Times in 2,200 Posts
Code:
```if(number< 0){
printf("Exiting....");
break;
}
else if (number >= 0 && number <=9)
digit(number);
else if ( !(number >= 0 && number <=9) )
printf("Sorry invalid number: Try again\n");```
__________________
Quote:
 The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

 Users who have thanked abduraooft for this post: calestia (12-21-2011)

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 11:58 AM.