Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Fun C++ Problem  (Read 3890 times)

0 Members and 1 Guest are viewing this topic.

jasonapawlak

  • Guest
Fun C++ Problem
« on: July 10, 2007, 01:05:12 PM »
Hey everyone,

I've used this site as a resource for such a long time, but never got into the forum... until now.  I thought a good way to get my feet wet would be to post a fun C++ problem I have enjoyed before.  Hopefully it is a new problem to some of you!

Give it your best!  (and don't post answers when you get them... let everyone have a fair chance)


Code: [Select]
#include<iostream>

using namespace std;

int main() {
  int i, n = 20;
  for (i=0; i<n; i--) {
    cout << "x" << endl;
  }
}

/*
Directions:
===========
Find three ways to make the above code print x 20 times
(by changing only one character)
*/


Click http://www.blarged.com/blog/CPP_Problem.cpp to download the source file straight to your box.

Best of luck!  Hopefully you do better than I did!

Dilbert

  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    Re: Fun C++ Problem
    « Reply #1 on: July 10, 2007, 04:49:11 PM »
    A tip to all: The current code is an infinite loop. I'm on it, because I can't resist. :)

    EDIT: Question: Does the "--" count as one character? It's certainly only one operator... ???
    "The geek shall inherit the Earth."

    jasonapawlak

    • Guest
    Re: Fun C++ Problem
    « Reply #2 on: July 10, 2007, 08:50:39 PM »
    A tip to all: The current code is an infinite loop. I'm on it, because I can't resist. :)

    EDIT: Question: Does the "--" count as one character? It's certainly only one operator... ???

    no, the '--' counts as two separate characters.  each keystroke is one character :-)

    its tough!

    Caprier



      Greenhorn

      Re: Fun C++ Problem
      « Reply #3 on: October 10, 2007, 11:30:08 AM »
      Nobody's playing? Well, I've found two. And I'd really like to know the one I'm missing.
      Has anyone found the three solutions?

      Dilbert

      • Moderator


      • Egghead

      • Welcome to ComputerHope!
      • Thanked: 44
        Re: Fun C++ Problem
        « Reply #4 on: October 10, 2007, 10:44:46 PM »
        Odd. It won't compile for me anymore.

        Permission denied
        ld returned 1 exit status


        is all I'm getting for an error message, though. Doesn't help me find out what's wrong. :(
        "The geek shall inherit the Earth."

        Caprier



          Greenhorn

          Re: Fun C++ Problem
          « Reply #5 on: October 10, 2007, 10:50:15 PM »
          Ok, found the third as soon as I woke up. Who said sleeping was a waste of time ? lol

          Dilbert, everything compiled for me. Sorry I can't help (real noob at programming).