Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tiso

Continual Loop

This topic is 6917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm still learning C and I'm trying to make a basic program that works off of certain numbers typed in. But, I've only learned up to the point where once the program does it's thing it shuts off. How do I keep this from happening so users can access another part of my program without restarting it? Any help is greatly appreciated. Edited by - Tiso on 5/10/00 2:38:35 PM

Share this post


Link to post
Share on other sites
Advertisement
quote:
...that works off of certain numbers typed in.


What do you mean? As in a loop? We need more information on what your trying to do, although it sounds as if you mean a loop.

If it is a loop, then you need two of them: One to control the entire program, and one to do the "stuff" loop . The main control loop keeps the program going until the USER wants to leave, and the "stuff" loop does "it's thing". Like so:

void main()
{
int done = 0;
int selection;
clrscr();
while(!done)
{
printf("\n\nEnter a number: ");
scanf("%d", &selection);
if(selection == 0)
{
done=1;
}
for(int loop=0; loop < selection; loop++)
{
printf("\nIteration %d", selection);
}
}
}


OK?

Edited by - Zipster on May 10, 2000 4:30:23 PM

Share this post


Link to post
Share on other sites
So I just add the code I want into that right?

What I meant was like when u enter 2 it does something and if you type in 1 it does something else, get it?

Share this post


Link to post
Share on other sites
well, id code it:

main()
{
int input;
int done = 0;
clrscr();
/*display options and then allow input
im trusting the last guy''s input command*/
scanf("%d", &input);
while(!done)
{
switch(input)
{
case 0:
done = 1;
break;
case 1:
/*do something*/
break;
/*etc.*/
default:
/*error message*/
}
clrscr();
}
return 0;
}

Share this post


Link to post
Share on other sites
Rats, I don''t get a thing that''s going on. I''ll wait I guess. Man! This is going to slow my program down quite a bit.

Share this post


Link to post
Share on other sites
Ohhh, so thats what you meant .
A switch statement like the one above will work. I''ll repost that code with some formatting :
main()
{
int input;
int done = 0;
clrscr();
/*display options and then allow input
im trusting the last guy''s input command*/
scanf("%d", &input);
while(!done)
{
switch(input)
{
case 0:
done = 1;
break;
case 1:
/*do something*/
break;
/*etc.*/
default:
/*error message*/
}
clrscr();
}
return 0;
}

Share this post


Link to post
Share on other sites
quote:
Okay, I got that. Do I just add my source code to that?


Well, actually, that WOULD be your source code (along with including headers, etc.). YOU just fill in the blanks!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!