I realize a there is an issue with my data overflowing, but my main concern is trying to re run the program at the end to start all over. I've looked through multiple examples through this website, but couldn't really find one that fit my need.
I am not sure if you can see the first part of my code, but I essentially tried to use someones do while example for my program but i just can't figure it out.
If anyone could give any suggestions I would greatly appreciate it!
I'm sure if i keep at it i'll figure it out eventually, but i thought this would be a good question for this website.
Here is my source code:
#include <stdio.h>
int main (void) {
int days;/* user will input number of days light will travel*/
int answer;
char buffer[256];
printf(" \n" );
printf("\t**-**-**-**Welcome to the LIGHT RAY!**-**-**-**\n");
printf(" \n" );
printf("\tTo get an idea of how unbelieveably fast light is!\n");
printf("\t come climb aboard the LIGHT RAY!\n", );
do
{
printf(" \n" );
printf(" \n");
printf("\tHow many days would you like to travel?\n");
scanf("%d", &days);
printf("processing...\n" ) /* fictional terminal computing information*/;
sleep(2);
printf("Initializing warp drive...\n" );
sleep(1);
printf("3\n" ) /* count down sequence*/;
sleep(1);
printf("2\n" );
sleep(1);
printf("1\n" );
sleep(1);
printf("SHROOOOM!\n" );
sleep(1);
int day_time=days * 86400/*86,400 seconds is equal to 1 day*/;
int distance=day_time*186000/*light travels 186,000 miles per second!*/;
printf("Congratulations, you have traveled %lld miles! \n",distance);
printf("Would you like another go?(yes, no)\n" );
scanf("%s\n", buffer );
}while (strcmp(buffer, "yes") !=0);
getchar();
return 0;
}
I think this should be enough to give you an idea:
For things like this i prefer instead something like this:
But if you insist to use yes/no instead of Y/N, then;
Output:
Please make notice that strcasecmp is found in strings.h and not in string.h.
Thank you all for your input your feedback is truly invaluable! I will likely refer back to this one day if i may need it
If any of you are interested here's my final product, even though I may continue to fiddle with it:
One last thought, would it be possible to change the action statement after the first iteration for example:
Do you wish to embark on a trip through the LIGHT RAY?
. . .
Congratulations...
Do you wish to take another trip? /repeat loop/
I also got some strange interactions when a character like "yes" is imputed for days_travel.
How would i cover for that, I'm thinking of a if then statement, but im not too sure how to structure it?