strange problem

Reply

Join Date: Oct 2004
Posts: 6
Reputation: navyblue is an unknown quantity at this point 
Solved Threads: 0
navyblue navyblue is offline Offline
Newbie Poster

strange problem

 
0
  #1
Mar 12th, 2005
#include<stdio.h>
main()
{int i;
do{
printf("*");
scanf("%d",&i);
}while(1);
}
this is a sample program,but u don't look down upon it
when u input a unnummber ,there will no stop!
i want to know why ???????????????????
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: strange problem

 
0
  #2
Mar 12th, 2005
Well it's not a strange problem considering it's doing what it is supposed to do.

First off, when posting code please use code tags. Read here

Second, main returns an int it should be int main(void).

Third, When writing please use complete sentences and use "you" not "u". Also using a bunch of question marks doesn't make your question more of a question.

Fourth, what your program is doing is looping while (1). This is saying while true repeat(any non zero number is "true"). What you were probably going for was something like this:
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int number;
  6. do
  7. {
  8. /*notice the spacing it makes your code much easier to read*/
  9. printf("*\n");
  10. printf("Enter 0 if you want to quit\n");
  11. scanf("%d",&number);
  12.  
  13. }while (number != 0);
  14.  
  15. return 0;
  16. }
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC