homework

언어2015. 9. 23. 17:23
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{
 srand((unsigned)time(NULL));
 int total = 0;
 int Correct_number = 0;
 //int Incorrect_number = 0;
 
 while (1 == 1)
 {
  char choice;
  int left_value = rand()%20;
  int right_value= rand()%20;
  int my_solve = 0;
  printf("%d + %d = ", left_value, right_value);
  scanf_s("%d", &my_solve);
  if (my_solve == left_value + right_value)
  {
   printf("Correct!   Continue? < y or n> ");
   fflush(stdin);
   choice = getchar();
   Correct_number++;
   total++;
  }
  else
  {
   printf("Incorrect!   Continue? < y or n> ");
   fflush(stdin);
   choice = getchar();
   //Incorrect_number++;
   total++;
  }
  if (choice != 'y')
  {
   break;
  }
 }
 printf("==> Your score : %d / %d <%.2f%%>\n", Correct_number, total, ((double)Correct_number / total) * 100);
 return 0;
}

 

 

'언어' 카테고리의 다른 글

예약시스템  (0) 2015.09.26
2*2 행렬  (0) 2015.09.26
네이버 지식인  (0) 2015.09.20
top coder 가 되기위해  (0) 2015.09.20
double_linked_list  (0) 2015.09.07