Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Codebreaking! (codebreaker.c) You are almost ready to graduate from the

ID: 3687629 • Letter: P

Question

Problem: Codebreaking! (codebreaker.c)

You are almost ready to graduate from the Ninja Academy. Only one set of lessons remains: code breaking. You will need to learn how to break numerical codes of varying lengths and difficulties.

The basic idea is this:

You begin by selecting a length and difficulty for the code. A set of numbers will be generated.

You will guess the magnitude and placement of each of the numbers.

Anything exactly correct will be revealed.

Anything with the correct value will be noted, but not revealed.

You can guess as many times as you want.

When the correct code is entered, the program will end.

A scaffold for this program has been provided. You must fill in the eight functions that are currently empty. After you write each function, you should test it before moving on. The main function should not be modified for the final submission.

Scaffold program:

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main(void) {

  int i, stime;

  long ltime;

  int x, j;

  int black = 0;

  int white = 0;

  int code[4];

  int easy[4];

  ltime = time(NULL);

  stime = (unsigned) ltime/2;

  srand(stime);

  code[i] = rand() % (9999-1000+1) + 1000;

  printf("%d", code[i]);

  printf(" **CODE BREAKER** ");

  printf("CHANCE #1 ");

  printf("Enter Guess: ");

  scanf("%d", &easy[4]);

  if(code[0] == easy[0]) {

    black = black + 1;

  }

  for(i = 1; i < 4; i++) {

    if(code[0] == easy[i]) {

      white = white + 1;

    }

  }

  if(code[1] == easy[1]) {

    black = black + 1;

  }

  if(code[1] == easy[0]) {

    white = white + 1;

  }

  for(i = 2; i < 4; i++) {

    if(code[1] == easy[i]) {

      white = white + 1;

    }

  }

  if(code[2] == easy[2]) {

    black = black + 1;

  }

  if(code[2] == easy[3]) {

    white = white +1;

  }

  for(i = 0; i < 2; i++) {

    if(code[2] == easy[i]) {

      white = white + 1;

    }

  }

  if(code[3] == easy[3]) {

    black = black + 1;

  }

  for(i = 0; i < 3; i++) {

    if(code[3] == easy[i]) {

      white = white + 1;

    }

  }

  if(black == 4) {

    printf("Congratulations! You guessed the number right! ");

  } else {

    printf("%d Black Marks %d White Marks", black, white);

  }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote