LaunchCode-Education-Archived / cs50x-live

The generic template version of Launchcode's CS50x curriculum. Fork this to create a repo for a particular city.
Creative Commons Zero v1.0 Universal
2 stars 5 forks source link

Exercise: Module 3, class 1 prep / Algorithmic Efficiency Quiz #36

Closed jesseilev closed 8 years ago

jesseilev commented 8 years ago

From @newjoiner on January 7, 2016 22:0

The program for question 1 does not return the biggest number. Does not have anything to do with the question, but just in case they copy the program over.

Original Program

#include <cs50.h>
#include <stdio.h>

int main(void)
{
  // set up example data
  int exampleArray[] = {12, -2, 0, 15, 27, 20, 6};
  int exampleSize = 7;

  bool seenOne = false;
  int currentMax = 0;

  for (int i = 0; i < exampleSize; i++)
  {
    if (!seenOne){
      currentMax = exampleArray[i];
    } else if (exampleArray[i] > currentMax){
      currentMax = exampleArray[i];
    }
  }
  printf(“The biggest number was %i\n”, currentMax);
}

Suggested Program

#include <cs50.h>
#include <stdio.h>

int main(void)
{

  // set up example data
  int exampleArray[] = {12, -2, 0, 15, 27, 20, 6};
  int exampleSize = 7;

  int currentMax = 0;

  for (int i = 0; i < exampleSize; i++)
  {
        if (exampleArray[i] > currentMax )
        {
             currentMax = exampleArray[i];
        } 

  }
  printf("The biggest number was %i\n", currentMax);
}

Copied from original issue: Launch-Code/cs50x-live-2016#140

jesseilev commented 8 years ago

From @newjoiner on January 8, 2016 17:36

forgot to mention @jesseilev

jesseilev commented 8 years ago

fixed!

@newjoiner Does this mean that in general you've been checking all our example code to make sure it works? If so, that would be a huge relief! I've been wondering how many buggy examples are out there..

newjoiner commented 8 years ago

I checked a couple that stood out, but I'll recheck.

jesseilev commented 8 years ago

Ok yeah, don't go out of your way, I was just curious