fork download
  1. #inclued<stdio.h>
  2. #inclued<stdlib.h>
  3. #inclued<time.h>
  4.  
  5. void Secret(void);
  6. void Guess(void);
  7.  
  8. int i, j, k, a_Count, b_Count;
  9.  
  10. int com_Ans[4], my_Guess[4], my_Guess_Temp;
  11.  
  12. int main (void)
  13. {
  14. Secret();
  15. while(a_Count !=4){
  16. Guess();
  17. Compare();
  18. }
  19. return 0;
  20. }
  21.  
  22.  
  23. void Secret(void){
  24. srand (time(NULL));
  25.  
  26. do {
  27. com_Ans[0]=rand()%10
  28. }while (com_Ans[0]==0);
  29.  
  30. do {
  31. com_Ans[1]=rand()%10
  32. }while (com_Ans[1]==com_Ans[0]);
  33.  
  34. do {
  35. com_Ans[2]=rand()%10
  36. }while (com_Ans[2]==com_Ans[1]) || com_Ans[2]==com_Ans[0];
  37.  
  38. do {
  39. com_Ans[3]=rand()%10
  40. }while (com_Ans[3]==com_Ans[2]) || com_Ans[3]==com_Ans[1] || com_Ans[3]==com_Ans[0];
  41.  
  42. printf("\nComputer Answer:");
  43. for(i=0; i<4; i++){
  44. printf("%1", com_Ans[i]);
  45. }
  46. }
  47.  
  48. void Guess(void){
  49. printf("\nPlease Input Your Guess:");
  50. scanf("%i", &my_Guess_Temp);
  51. my_Guess[0] = my_Guess_Temp/1000;
  52. my_Guess[1] = my_Guess_Temp/100%10;
  53. my_Guess[2] = my_Guess_Temp/10%10;
  54. my_Guess[3] = my_Guess_Temp/10%;
  55. }
  56.  
  57. void Compare(void){
  58. a_Count=0
  59. b_Count=0
  60. for(i=0;i<4;i++){
  61. if(my_Guess[i]==com_Ans[i]){
  62. a_Count=a_Count+1
  63. }
  64. }
  65. for(i=0;i<4;i++){
  66. if(my_Guess[i] !=com_Ans[i]){
  67. for(j=0; j<4; j++){
  68. if(i!=j &&; my_Guess[i]==com_Ans[j]){
  69. b_Count=b_Count+1;
  70. }
  71. }
  72. }
  73. }
  74. printf{"Computer Respond: %i A %i B \n",a_Count,b_Count};
  75. }
  76.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:2: error: invalid preprocessing directive #inclued
prog.c:2:2: error: invalid preprocessing directive #inclued
prog.c:3:2: error: invalid preprocessing directive #inclued
prog.c: In function ‘main’:
prog.c:17: warning: implicit declaration of function ‘Compare’
prog.c: In function ‘Secret’:
prog.c:24: warning: implicit declaration of function ‘srand’
prog.c:24: warning: implicit declaration of function ‘time’
prog.c:24: error: ‘NULL’ undeclared (first use in this function)
prog.c:24: error: (Each undeclared identifier is reported only once
prog.c:24: error: for each function it appears in.)
prog.c:27: warning: implicit declaration of function ‘rand’
prog.c:28: error: expected ‘;’ before ‘}’ token
prog.c:32: error: expected ‘;’ before ‘}’ token
prog.c:36: error: expected ‘;’ before ‘}’ token
prog.c:36: error: expected ‘;’ before ‘||’ token
prog.c:40: error: expected ‘;’ before ‘}’ token
prog.c:40: error: expected ‘;’ before ‘||’ token
prog.c:42: warning: implicit declaration of function ‘printf’
prog.c:42: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:44: warning: conversion lacks type at end of format
prog.c:44: warning: too many arguments for format
prog.c: In function ‘Guess’:
prog.c:49: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:50: warning: implicit declaration of function ‘scanf’
prog.c:50: warning: incompatible implicit declaration of built-in function ‘scanf’
prog.c:54: error: expected expression before ‘;’ token
prog.c: At top level:
prog.c:57: warning: conflicting types for ‘Compare’
prog.c:17: warning: previous implicit declaration of ‘Compare’ was here
prog.c: In function ‘Compare’:
prog.c:59: error: expected ‘;’ before ‘b_Count’
stdout
Standard output is empty