Thread: explain this code please

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    15

    explain this code please

    Before i start i would just like to say this. If you are looking to learn c++, dont get "Learn to program with c++" by john smiley.

    I have posted this two times already, but no one has actually explained the whole thing.

    First part

    Code:
    for (int i = 0; i < morebankingbusiness.length(); i++)
    What i get out of that is that the loop is called i and it starts at 0. As long as i is less than the length of morebankingbusiness then the interger i will increase 1. correct me if im wrong which i think i am.

    Second part

    Code:
    float adjustment = 0;
    char response[256];
    string morebankingbusiness
    I get that adjustment can be a decimal but i have no idea what "char response[256]" and "string morebankingbusiness" is.

    Third part

    further in the code there is this

    Code:
    cin.getline(response,256)
    
    if strlen(response) == 0)...
    what does that all mean.

    Fourth part

    Code:
    else
    if (atoi(response) <1...
    what does that all mean.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    it means you need to read more...

    >for (int i = 0; i < morebankingbusiness.length(); i++)

    it means loop until 'i' is greater than or equal to 'morebankingbusiness.length()'

    >
    float adjustment = 0;
    char response[256];
    string morebankingbusiness
    <

    'adjustment' is a float point variable i.e. can have decimal places

    'response' is an array of 256 char's

    'morebankingbusiness' is a variable of type 'string' this a C++ class... for more advanced safer string handling...

    >
    cin.getline(response,256)

    if strlen(response) == 0)...
    <

    cin.getline(response,256)

    reads a maximum of 255 characters from input and sets the last as character in the array to null.

    if strlen(response) == 0)

    strlen counts the length of a string
    if the length of response is 0, do whatever is in the if statement...

    >
    else
    if (atoi(response) <1...
    <

    atoi converts a string to an int, so...
    if whatever int is contained in 'response' is less than zero do whatever is in the if statement
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing Code
    By ILoveVectors in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2005, 12:27 AM
  2. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  3. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM