Prince
Prince

Reputation: 47

count value and back again to the beginning of the code when user input numbers

after the program count what use input, it will printout the value, and after it the program will ask to continue or not, and if i press 'Y' the programm will start from the beginning when user input number. the question is how to make the program back to the beginning if user press 'Y'?

#include <stdio.h>
#include <stdlib.h>
void VOne();
int main(void) {
  VOne();
  return 0;
}

void VOne() {
  int i,quiz,exer,test,Final,FV,back;
  char again;
  while (1) {

    printf("Input Value : ");
    scanf("%d %d %d %d",&quiz,&exer,&test,&Final );
    FV = 0.10+(0.10*quiz)+(0.15*exer)+(0.30*test)+(0.35*Final);
    printf("%d\n",FV );
    if (FV >= 75) {
      printf("You pass the this class\n" );
    }
    else {
      printf("You've to take this class again in the next term\n");
    }
    printf("You want to input again?\n'Y'or'N\n");
    scanf("%c ",&again );
    if (again == 'y') {
      continue;
    }
  }
  return;
}

Upvotes: 0

Views: 41

Answers (1)

Sayed Sohan
Sayed Sohan

Reputation: 1499

This should work.

#include <stdio.h>
#include <stdlib.h>
void VOne();
int main(void) {
  VOne();
  return 0;
}

void VOne() {
  int i,quiz,exer,test,Final,FV,back;
  char again;
  while (1) {

    printf("Input Value : ");
    scanf("%d %d %d %d",&quiz,&exer,&test,&Final );
    FV = 0.10+(0.10*quiz)+(0.15*exer)+(0.30*test)+(0.35*Final);
    printf("%d\n",FV );
    if (FV >= 75) {
      printf("You pass the this class\n" );
    }
    else {
      printf("You've to take this class again in the next term\n");
    }
    printf("You want to input again?\n'Y'or'N\n");
    scanf(" %c ",&again );
    if (again == 'y' || again == 'Y') {
      continue;
    }
    else break;
  }
  return;
}

Upvotes: 1

Related Questions