Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Lost pages

Name: Anonymous 2009-03-19 13:00

I'm having a bit of trouble. My professor printed out a page of c++ examples and the main bit of information explaining what it does isn't there.
Can you please help? The only lines I need help with are the ones indicated by a comment.

#include <iostream>

//line below
int stonetolb(int);

int main()
{
    using namespace std;
    int stone;
    cout << "enter the weight in stone: ";
    cin >> stone;
    cin.get();
    //line below
    int pounds = stonetolb(stone);
    cout << stone << " stone = ";
    cout << pounds << " pounds" << endl;
    cin.get();
    return 0;
}

//this block
int stonetolb(int sts)
{
    return 14 * sts;
}


Thanks in advance.

Name: Anonymous 2009-03-19 13:18

The first line declares a function called stonetolb to convert stone to pounds. The function takes as parameter an integer which is the weight in stones and return an integer which is the weight in pounds.

In the second line the function stonetolb is called to convert the weight in stone entered by the user into pounds.

The last block defines the function stonetolb. We convert the weight in stone to pounds by multiplying the weight in stone by 14.

Hope this helped.

Name: Anonymous 2009-03-19 13:24

int stonetolb(int);

This is a function prototype. It's used because c++ compilers are too stupid to see if the function exists by themselves, so you tell it that it exists this way so you can use it in main.  Alternatively you could just have the function definition before main and that would also satisfy the compiler(since it would now know that stonetolb exists when its called later on in main.


int stonetolb(int sts)
{
    return 14 * sts;
}

This is a function. Also known as a reusable piece of code. Anytime you needed to convert stonetolb you could call this function.  This particular function takes an integer as an argument(int sts) and returns another integer.  Good day sir.

Name: Anonymous 2009-03-19 13:28

>>1-3
SPAWHBTC

Name: Anonymous 2009-03-19 16:21

Goddamn dirty first years.

Name: Anonymous 2009-03-19 20:02

>>1-3
Jesus F. Christ, I don't know whats worse: the fact that /prog/ is HELPING PEOPLE! now or the fact that IHBT by /prog/ HELPING PEOPLE!

I honestly hope this shit stops.

Name: Anonymous 2009-03-21 0:43

GREEEEEEN

Marijuana MUST be legalized.

BBCode MASTERS smoke WEED!

Name: Anonymous 2009-03-21 1:24

Shove your homework up your ass.

Name: Anonymous 2009-03-21 9:43

>>6
Don't help him!

Name: Trollbot9000 2009-07-01 10:58

Return n fact b.

Name: Anonymous 2011-01-31 21:13

<-- check em dubz

Name: tray 2012-03-14 17:12

you better be

Don't change these.
Name: Email:
Entire Thread Thread List