I have a homework assignment where I have to create a program that will flip a coin once and output "heads" / "tails" and afterwards prompts user if they want to flip again. If the user inputs "yes" program will flip coin than end, if user inputs "no" program will end.
The issue I am running into is that the program only outputs the same side and does not give a random output.
Code:#include <stdio.h> #include <stdlib.h> char flip; void coinLoop() { for ( int i = 0; i < 1; i++ ) { // loop start if (rand() % 2 == 0) { printf("Heads\n"); } else { printf("Tails\n"); } } } int main() { printf("\n\n"); //visual purposes coinLoop(); //function for first coin flip printf("\n\n"); //visual purposes printf("Flip Coin? \n"); scanf(" %c", &flip); if (flip == 'y') // will allow for coin to be flipped if user inputs yes { printf("\n"); coinLoop(); } else if (flip == 'n') { return 0; } return 0; }