Jump to content

Guess the missing line!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
43 replies to this topic

#1
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Another suggestion from Phil (morefood2001) that sounded interesting. The purpose of this game is to guess the missing line of code. It doesn't have to be an entire line and could just be a variable, function name, etc. When posting your code blank out the missing variable/code/line with ????? and offer upto 4 choices to select from.

Rules
1) The previous guess must be answered before you can post a new one
2) Don't post a new one until the guess is confirmed (by the author or other members)
3) Show what the expected results should display.
4) Offer choices


I'll start with a simple example:

Code:
$strCode = "CodeCall";
???? $strCode;

Results:

Quote

CodeCall

Question
What should go in place of the ???? in order for the above results to be displayed?

  • cout
  • printf
  • echo
  • display

Go!

#2
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
Answer is echo

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Correct! Post your code.

#4
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts

int nums[3];

int i=1;

int result;

cin>>nums[0]>>nums[1]>>nums[2]>>nums[3];

result=nums[0];

while(true)

{

     if(result<nums[i]) rerult=nums[i];

     i++;

     ????

}

cout<<"the biggest value is "<<result;

output:

8

12

9

7

the biggest value is 12

choices:
1. If(i>2) continue;
2. If(i>3) breaK;
3. If(i==3) break;
4. If(i==3) continue;

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If(i>3) breaK;
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
Muahahaha
you fell in my trap the k in the breaK is capital theres no such word
try again

#7
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
Wing's makes sense, but how about 3. If(i==3) break;?

#8
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
Thats the correct answer
its true that '>' makes more sense but it wont compile

#9
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
Sadly though you will never look at case 3 in that code and whats the point of making a case 3 if you aren't going to look at it?

Ok, so here is my example from real code that I have wrote:

<?php

/**
 * @author Phil Matu
 * @copyright 2007
 * @use To delete all IP Tracker records older than 1 day, can be run as a cron job.
 */
 
 //This is meant to run on its own every day at midnight EST.  No interaction required.

if (empty($dbusername)) { //incase login variables aren't set
 ???????????????????????
 }

$dbconn=mysql_connect($dbserver, $dbusername, $dbpassword) or die ("No connection: ".mysql_error());

$q = mysql_db_query($dbname,"DELETE FROM iptracker WHERE Time < DATE_SUB(NOW( ),INTERVAL 86400 SECOND)") or die (mysql_error()); //query deletes last 24 hours of data

?>

Choices:
1. $dbusername = "podnet_live";
2. include ("config.php");
3. $dbusername = array ("podnet_live", "password", "localhost");
4. $dbusername = new db();

#10
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I'm going with #1 although I would put something like:

die("Username not set!");


#11
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
Nope. Try again :)

#12
Guest_Jordan_*

Guest_Jordan_*
  • Guests
It has to be #2 then, assuming you have a config file and it contains all your properties.