New C++ user, help with program?

Discussion in 'OT Technology' started by Danja, Apr 1, 2006.

  1. Danja

    Danja New Member

    Joined:
    Nov 16, 2005
    Messages:
    63
    Likes Received:
    0
    I'm trying to make a program in C++. I'm a student but this isn't homework, its just something i've been doing for fun. Anyway, one certain part of it isn't working and I can't figure out why: Here is the part of the program:

    #include <iostream.h>
    #include "apstring.h"

    double process(int age, int weight, int feet, apstring hair, apstring eyes, apstring first, apstring middle, apstring last);
    void judgement (apstring first, apstring middle, apstring last, double average);

    int main()
    {

    apstring choice2;

    cin >> choice2;

    cout << endl;
    while (choice2 != "yes" && choice2 != "no")
    {
    if (choice2 == "yes")
    {
    double process(int age, int weight, int feet, apstring hair, apstring eyes, apstring first, apstring middle, apstring last);
    void judgement (apstring first, apstring middle, apstring last, double average);
    }

    else if (choice2 == "no")
    {
    cout << "Aww, thats too bad. Now you'll be curious forever!";
    break;
    }

    else
    {
    cout << "Please type yes or no." << endl;
    cin >> choice2;

    }

    }

    return 0;

    }

    double process(int age, int weight, int feet, apstring hair, apstring eyes, apstring first, apstring middle, apstring last)
    {
    cout << "process working." << endl;
    return 2.3;
    }

    void judgement (apstring first, apstring middle, apstring last, double average)

    {
    cout << "judgement working." << endl;
    }

    When I run the program, even if I enter "yes," the program closes and doesn't run the functions. Am I not allowed to put functions in an if statement? whats wrong?
     
  2. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    what is in apstring.h?

    are you sure that string class has the == and >> operators overloaded correctly?

    If not, then why not use the string class included in the STL? I bet if you use string instead of apstring that it iwll work
     
  3. samm

    samm Next in Line

    Joined:
    Dec 22, 2000
    Messages:
    2,630
    Likes Received:
    0
    Location:
    San Jose, CA
    iostream.h is nonstandard, iostream is the correct header. What is apstring.h?

    You are allowed to put functions in an if statement.
     
  4. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    On review of your code, your if statements will never execute

    it's saying,

    while choice is not "yes" and it is not "no", check to see if it's "yes" or "no"

    try changing it to something like
    Code:
    while (choice2 != "exit")
    
     
  5. Danja

    Danja New Member

    Joined:
    Nov 16, 2005
    Messages:
    63
    Likes Received:
    0
    Ok, I tried that and it work. Now I'm only getting three errors. It doesn't like my process function. It says "error C2660: 'process' : function does not take 0 parameters." I have it declared as taking 8 parameters, just like it is. :dunno:
     
  6. Shibboleth

    Shibboleth teh mad Plato skillz

    Joined:
    Sep 29, 2004
    Messages:
    1,769
    Likes Received:
    0
    this is how you call a function
    Code:
    void function(int x);
    
    int main()
    {
         function(10);
    }
    
    void function(int x)
    {
        cout<<"We're in the function"<<endl;
        cout<<x<<endl;
    }
    
    I think maybe you should hit the books some more
     

Share This Page