Thread: noob

  1. #16
    1337
    Join Date
    Jul 2008
    Posts
    135
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        
        string x = "How are you?";
        for (int x=0;x<10;x++);
        
        
        
        {
             cout<<x<< endl;
        }
         
        
        
        
        
        
        cin.get();
        return EXIT_SUCCESS;
    }

    it doesnt work, it prints only once. what i need is 10

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It does exactly what you told it to, just not what you wanted it to do. You have an extra character at the end of line 10.

  3. #18
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    What tabstop is trying to say is there is a typo here:
    Code:
    for (int x=0;x<10;x++);
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

  4. #19
    1337
    Join Date
    Jul 2008
    Posts
    135
    I dont get it. how should it be typed?

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You have one extra character at the end. Remove the extra character at the end.

  6. #21
    1337
    Join Date
    Jul 2008
    Posts
    135
    Thanks it works...... but it prints number 0,1,2,3,4........ that is not what i want. what i want is for it to print "how are you"

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Well, you're printing x, aren't you? x is going from 0 to 99, so hey. If you want to print "how are you", have it print "how are you".

  8. #23
    1337
    Join Date
    Jul 2008
    Posts
    135
    but how??? i am new to this

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You put the literal words "how are you" (including the quotes) in the program, in the print statement. You don't want to print x, because x is your counter. You want to print "how are you".

  10. #25
    1337
    Join Date
    Jul 2008
    Posts
    135
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        
        string x = "How are you?";
        for (int x=0;x<10;x++);
        
        
        
        {
             cout<<"how are you"<< endl;
        }
         
        
        
        
        
        
        cin.get();
        return EXIT_SUCCESS;
    }
    it prints only once. i want it to print 10 times, how?

  11. #26
    1337
    Join Date
    Jul 2008
    Posts
    135
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        
        string x = "How are you?";
        for (int x=0;x<10;x++);
        
        
        
        {
             cout<<"how are you"<< endl;
        }
         
        
        
        
        
        
        cin.get();
        return EXIT_SUCCESS;
    }
    it prints only once. i want it to print 10 times, how?

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by valthyx View Post
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        
        string x = "How are you?";
        for (int x=0;x<10;x++);
        
        
        
        {
             cout<<"how are you"<< endl;
        }
         
        
        
        
        
        
        cin.get();
        return EXIT_SUCCESS;
    }
    it prints only once. i want it to print 10 times, how?
    We've been here before, oh yes:
    Quote Originally Posted by tabstop View Post
    It does exactly what you told it to, just not what you wanted it to do. You have an extra character at the end of line 10.
    Is it at all possible for you to think for five seconds before you post? This is exactly the problem you had before, and you managed to get it fixed -- so don't put the error back!

  13. #28
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Well it was less than two hours ago since that mistake was explained and understood, and it's back already.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #29
    1337
    Join Date
    Jul 2008
    Posts
    135
    cant you all just write a code for me...at least at the error part.. i have been trying but could not succeed. Please help.... i need a straight forward answer...

  15. #30
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    I think tabstop and I have explained it before. It's the same mistake that you did before. Boy, this is "fun"...

    And for the part where you asked us about the whole code, the answer is no. We don't do your homework. It is better to understand the problem if you do it yourself.
    ERROR: Brain not found. Please insert a new brain!

    “Do nothing which is of no use.” - Miyamoto Musashi.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob Q: How to read a value of a byte in binary?
    By Hitsuin in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 02:46 PM
  2. Noob printf question
    By lolguy in forum C Programming
    Replies: 3
    Last Post: 12-14-2008, 08:08 PM
  3. I'm a noob and I need help.
    By nifear4 in forum C Programming
    Replies: 17
    Last Post: 10-14-2008, 01:20 PM
  4. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  5. noob: compiling error... plz help!
    By chosii in forum C Programming
    Replies: 2
    Last Post: 05-10-2002, 05:53 AM