Is there a way to restart a program from the biggining.
What I want is something like:
printf ("data is wrong do you want to re-enter it or do onther student.\n");
I like to give the person a chose to reenter it or just start over the program.
I know there a way to end just wander if they have one for this. If not I have to do some breack loop back in the int main() and I do not really want to do that.
Thanks
C Restarting a program
Started by cook777, Mar 23 2009 01:30 PM
3 replies to this topic
#1
Posted 23 March 2009 - 01:30 PM
|
|
|
#2
Posted 23 March 2009 - 03:42 PM
I'm tempted to say use a goto statement. But thats not very popular or favored amongst programmers. It would be nice to see your code.
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:
#3
Posted 23 March 2009 - 05:01 PM
fread said:
I'm tempted to say use a goto statement.
for ( ;; )
{
int result;
result = 0;
result = getInput();
if ( 0 == result )
{
// fail;
continue;
} // if
break;
} // for
#4
Posted 24 March 2009 - 10:59 AM
Ok I not going to put the real program in here because its too long. So I just wroght this one that should have the idea. There maybe mitakes I have not run in though compiler or debuged it.
Ya this is much more simple code but the idea is there. Hope you guys understand it better now.
#include <stdio.h>
#include <ctype.h>
void getClass (int class);
void getHours (int hours);
int main ()
{
int class[1]; int hours[1]; int x=1; char option;
do{
getClass (class);
getHours (hours);
printf ("Do you want to do anther student? Y for yes and N for No n");
scanf ("%c",option); toupper(option)
if (option == 'N')
x=0;
}while (x==1);
return 0;
}
void getClass (int class)
{
printf ("Enter in the class number");
scanf ("%d",class[0]);
printf ("\n");
}
getHours (int hours)
{
case 1234 : hours[0] = 3;
case 2134 : hours[0] = 1;
case 1243 : hours[0] = 3;
case 1324 : hours[0] = 4;
default : // This is were I like it to start the program over.
}
Ya this is much more simple code but the idea is there. Hope you guys understand it better now.
Edited by cook777, 24 March 2009 - 11:00 AM.
fix code


Sign In
Create Account


Back to top









