954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

do - while looping help

what is the program of do while that ...
you can type any number but when u type zero it will stop the program?
thanks for the help
peace!

CloudZELL91
Newbie Poster
7 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

You sound incredibly lazy. Seeing as this is a trivial program, try it yourself first.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

yes, narue maybe you right am lazy...am still new on this....


main()

{int x=1

do{ printf("%d",x);
x++;
if(x==0),
{
printf("end")
}
}while(x>0)
,,,,,,
is this right?

CloudZELL91
Newbie Poster
7 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 
You sound incredibly lazy. Seeing as this is a trivial program, try it yourself first.


yes, narue maybe you right am lazy...am still new on this....

is my program right? the one i post?

CloudZELL91
Newbie Poster
7 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

Replace ++x; with scanf("%d", &x); and your logic is reasonably sound. Otherwise it's broken because the loop will never end[1].


[1] It will end, but not in a well-defined way.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

[1]....
main()

{int x=1

do{ printf("%d",x);
scanf("%d", &x);
if(x==0),
{
printf("end")
}
}while(x>0)

...

[2]
main()

{
scanf("%d", &x);

int x=1;

do{ printf("%d",x);
x++;
if(x==0),
{
printf("end")
}
}while(x>0)

,,,,,

the program will be shown like you said in the number one....
but if i do it like in the number 2...is it also right?

CloudZELL91
Newbie Poster
7 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 
but if i do it like in the number 2...is it also right?


No. Might I recommend dropping down a level and learning basic programming through pseudocode? Your C is just awful, and not understanding the the fundamentals won't help.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
No. Might I recommend dropping down a level and learning basic programming through pseudocode? Your C is just awful, and not understanding the the fundamentals won't help.


hehehe..yes narue your right am really awful in c coz i skip c programming for atleast a year and i forgot everything and now am doing it again haha...
so thats it thanks a lot man,, for your time....
,,,,i'll just use the program that u gave...
peace!

CloudZELL91
Newbie Poster
7 posts since Jun 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You