Thread: help me with this

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    3

    Unhappy help me with this

    hello friends!
    how do i read this line:

    calc <op1> <op> <op2>

    I need op,op1,op2 in a function.
    I hope the example helps u.
    ex: calc 40 / 8
    output: 40/8=5
    Tks!
    Last edited by atemlos; 05-19-2003 at 07:46 AM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    try it.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    How do you read it?????

    calc is the name of the function
    op1 and op2 are the operands (the numbers)
    and op is the operator (+, -, *, /, etc)

    So write a function that takes those 3 parameters, and returns a value in the appropriate data type (int, double, etc).

    (Is that what you're asking?)

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    195
    He means that his program reads that line from user input and solves it.

    alright man, if you have apstring (if you dont have it download it from anywhere)

    apstring has this function called find(character)
    apstring also has a function called substr (int starpos, int howmanyspaces)

    apstring uses classes so lets say you do this

    NOT ACTUALY CODE

    first declare it
    apstring input, temp;
    int ptr; //points to the pos of found character

    ptr=input.find(" "); //find a space
    temp=input.substr(0,ptr); //temp will now be the first number

    Then see wat temp is then change the space to a "*" so you dont find it again.

    input[ptr]="*";

    next just find the next space and find the substring text etc.

    i hope you get it

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    3

    Unhappy new statement

    read: i have 4 strings and whit a space between them, but the 2. and the 4. are integers. ho do i make int from the strings.

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Look up atoi function. This will convert a c-style string (char array) to an integer.

    It's in <stdlib.h>, or <cstdlib>.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    I just looked at your code in the other thread.

    First lesson:
    Don't make multiple threads for the same issue.

    Second:
    You are NOT reading the user input into your strings. I don't have much time to go into it now -- have to go take an exam -- but one way is, instead of
    Code:
    char d[4];
    you could use
    Code:
    char a[4];
    char b[4];
    char c[4];
    char d[4];
    then, after
    Code:
    printf("type line:\n");
    you could put a few of these:
    Code:
    cin << a;
    etc...
    Then you'll have 4 separate strings -- easy to work with.

  8. #8
    Registered User
    Join Date
    May 2003
    Posts
    195
    most semi-cool programs enter it in 1 line =D

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Probably better to have a goofy program that works than a semi-cool one that doesn't.

Popular pages Recent additions subscribe to a feed