Thread: noob

  1. #1
    1337
    Join Date
    Jul 2008
    Posts
    135

    noob

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <time.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        
        
     char *count="HOw Are you";
     
        
        
        
        
        
                for (count<100);
                
                cout<< count<<endl;
                
                      
                  
        
        cin.get();
        return EXIT_SUCCESS;
    }

    i got an error during compilation, please help. What i ma trying to do is let the program prints out 100 "how are you"

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You're in the right forum now, but you still need to actually look up for loops in C++.

  3. #3
    1337
    Join Date
    Jul 2008
    Posts
    135
    what is loops in C++? mind explaining?

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You need a book or tutorial.

  5. #5
    1337
    Join Date
    Jul 2008
    Posts
    135
    why cant you guys just help me.. please

  6. #6
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Because you want us to teach you the language practically from scratch, plus you've already been told what is wrong.

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    count doesnt need to be a character pointer - look up strings.

    A for loop has 3 conditions not one.

    for ( 1 ; 2; 3 )
    Double Helix STL

  8. #8
    1337
    Join Date
    Jul 2008
    Posts
    135
    char count="HOw Are you";






    if (count<100);

    cout<< count<<endl;

    something like this??

    but it doesnt work,

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Not even close.

    For one:

    Code:
    std::string str = "How are you?"; // this is a string
    Double Helix STL

  10. #10
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You want help? ...this part:
    Code:
    for (count<100);
    Makes no sense syntactically or logically. You need to first understand the syntax of a simple for loop. For simplicity sake, there are three parts that go in the parenthesis and they are separated by semicolons. Typically some kind of initialization step, followed by a test condition and then possibly an incrementation step. You have only one, the test, and even that part is wrong since you're trying to test the address of a pointer against an integer (syntactically speaking, that part alone is fine however it is not what you want to happen there). The last thing wrong with that is the semicolon ';' at the very end. Placed where it is, the semicolon results in... NOTHING. That is the part where you put the statement (followed by a semicolon) that you wish to have executed but since there is no statement there nothing would happen.

    A simple single-statement for loop would look like:
    Code:
    for( initialization; test condition; increment )
        statement;
    What it looks like you have is :
    Code:
    for( test condition );
    At the very least, you want another integer variable that can be used as a loop counter. This should be initialized to 0 in the "initialization" part of the for loop. Then it should be compared against the value 100 like you are currently doing with the count variable. Next this counter should be incremented. Those three steps can all be in the parenthesis of the for loop. Lastly, you need to put the output step (the cout) after the ')' parenthesis, but before the semicolon.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It is even impossible to tell what you expect this program to do! What do you mean by comparing if "HOw are you?" is smaller than 100?

    You really need to read a tutorial.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    This is the most ignorant help request I've seen in my entire time on this forum. I can't believe people are actually giving you answers.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Hmmm... stop explorer.exe and print "How are you" a hundred times to the screen. Sounds like an interesting application you're making.

  14. #14
    1337
    Join Date
    Jul 2008
    Posts
    135
    ok, this is my pseudo code
    str = "how are you";

    print "how are you";

    dont stop printing until it reaches 100 times
    this is what i am trying to do, help me please.

  15. #15
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    You know, you should learn your C++ basics before asking here. It's pretty trivial IMHO once you've got all the basics right. Just learn from the tutorial here. Especially about loops (for / while) like the guys mentioned. Also you should learn a bit about data types. It seems like your understanding of them is somewhat lacking seeing as you tried to compare a string (pointer to char) against an int.
    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