Program not working properly..HELP!!

I've written a program, but I don't know what's wrong with it..
you're supposed to pick an operation, and the program takes you to that operation, when you're done it quits.

the problim is, no matter what operation I choose, I have to go through all operations!!!

Please compile the code and test.. Please help me..

[code]
/********************************
/Author: Amer Adeeb Al-Sadiq *
/E-mail: nectron101@hotmail.com *
/Project: Geometric Calculator. *
/Version: 1.0 *
/Date: 15/01/2004 *
/*******************************/

#include
#include
using namespace std;

int main()
{
int selec, width, length, recpri, recar, squpri, squar, tripri;
int parpri, parar, liseg, liseg2, liseg3, hight, base;
int radius, side;
double circir, cirar, triar;
cout << " Geometric Calculator" << endl;
cout << " Version 1.0 " << endl << endl;
cout << " By: Amer Al-Sadiq" << endl;
cout << " nectron101@hotmail.com" << endl << endl << endl;
cout << "Please choose an operation:" << endl << endl;
cout << "1.Reactangle Perimeter." << " 2.Rectangle Area." << endl << endl;
cout << "3.Square Perimeter." << " 4.Square Area." << endl << endl;
cout << "5.Triangle Perimeter." << " 6.Triangle Area." << endl << endl;
cout << "7.Circle Circumference." << " 8.Circle Area." << endl << endl;
cout << "9.Parallelogram Perimeter." << " 10.Parallelogram Area." << endl << endl << endl;
cout << "Enter operation number:";
cin >> selec;

switch (selec)
{
case 1: inline int one();
break;

case 2: inline int two();
break;

case 3: inline int three();
break;

case 4: inline int four();
break;

case 6: inline int five();
break;

case 7: inline double seven();
break;

case 8: inline double eight();
break;

case 9: inline int nine();
break;

case 10: inline int ten();
break;

default:
cout << "Error! unknown input, quitting..." << endl;
break;
}

int one();
{
cout << "Please enter length:";
cin >> length;
cout << "Please enter width:";
cin >> width;
recpri = (2*length)+(2*width);
cout << "
Rectangle's Perimeter = " << recpri << endl;
}

int two();
{
cout << "Please enter length:";
cin >> length;
cout << "
Please enter width:";
cin >> width;
recar = (length*width);
cout << "
Rectangle's Area = " << recar << endl;
}

int three();
{
cout << "Please enter line segment:";
cin >> liseg;
squpri = (4*liseg);
cout << "
Square's Perimeter = " << squpri << endl;
}


int four();
{
cout << "Please line segment:";
cin >> liseg;
squar = (liseg*liseg);
cout << "
Square's Area = " << squar << endl;
}

int five();
{
cout << "Please enter first line segment:";
cin >> liseg;
cout << "Please enter second line segment:";
cin >> liseg2;
cout << "Please enter third line segment:";
cin >> liseg3;
tripri = (liseg+liseg2+liseg3);
cout << "
Triangle's Perimeter = " << tripri << endl;
}

double six();
{
cout << "Please enter hight:";
cin >> hight;
cout << "
Please enter base:";
cin >> base;
triar = (0.5*hight*base);
cout << "
Triangle's Area = " << triar << endl;
}

double seven();
{
cout << "Please enter radius:";
cin >> radius;
circir = (3.1415926*radius);
cout << "
Circle's Circumference = " << circir << endl;
}

double eight();
{
cout << "Please enter radius:";
cin >> radius;
cirar = (3.1415926*radius*radius);
cout << "
Circle's Area = " << recar << endl;
}

int nine();
{
cout << "Please enter base:";
cin >> base;
cout << "Please enter side:";
cin >> side;
parpri = ((2*base)+(2*side));
cout << "
Parallelogram's Perimeter = " << parpri << endl;
}

int ten();
{
cout << "Please enter hight:";
cin >> hight;
cout << "
Please enter base:";
cin >> base;
parar = (hight*base);
cout << "
Parallelogram's Area = " << parar << endl;
}

system ("pause");
return 0;
}

[/code]

Comments

  • : I've written a program, but I don't know what's wrong with it..
    : you're supposed to pick an operation, and the program takes you to that operation, when you're done it quits.
    :
    : the problim is, no matter what operation I choose, I have to go through all operations!!!
    :
    : Please compile the code and test.. Please help me..
    At first glance it looks to me like you shouldn't have the ;'s after the sub prototypes. For example:-

    : int four();
    : {

    Should just be:-

    int four()
    {

    Jonathan


    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • : : I've written a program, but I don't know what's wrong with it..
    : : you're supposed to pick an operation, and the program takes you to that operation, when you're done it quits.
    : :
    : : the problim is, no matter what operation I choose, I have to go through all operations!!!
    : :
    : : Please compile the code and test.. Please help me..
    : At first glance it looks to me like you shouldn't have the ;'s after the sub prototypes. For example:-
    :
    : : int four();
    : : {
    :
    : Should just be:-
    :
    : int four()
    : {
    :
    : Jonathan
    :
    :
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    :
    : No, I tried that but I get about a thousand errors..
    Any other idea?

  • : : : I've written a program, but I don't know what's wrong with it..
    : : : you're supposed to pick an operation, and the program takes you to that operation, when you're done it quits.
    : : :
    : : : the problim is, no matter what operation I choose, I have to go through all operations!!!
    : : :
    : : : Please compile the code and test.. Please help me..
    : : At first glance it looks to me like you shouldn't have the ;'s after the sub prototypes. For example:-
    : :
    : : : int four();
    : : : {
    : :
    : : Should just be:-
    : :
    : : int four()
    : : {
    : :
    : : Jonathan
    : :
    : :
    : : ###
    : : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
    : :
    : No, I tried that but I get about a thousand errors..
    : Any other idea?
    :
    You really should post errors, or some of them anyway. :-) But anyway, it's most likely because I forgot the mention that you need to put lines like:-

    int four();

    Near the top of your program - before the main() function - for each of your functions. You can leave the the definition of the subs where they are, but you do need to declare them before you use them.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • [b][red]This message was edited by Extrasolar at 2004-1-15 15:33:46[/red][/b][hr]
    [purple]
    It is because you are declaring your functions INSIDE of main. remove the ; at the end of the function i.e func1(); should be func1() and place them OUTSIDE of main before int main().

    [code]
    you have:

    int main()
    {
    blah blah blah
    func1();
    {
    code
    }
    func2();
    {
    code
    }
    func3{};
    {
    code
    }
    ...etc
    return 0;
    }

    You should have:

    func1()
    {
    code
    }
    func2()
    {
    code
    }
    func3()
    {
    code
    }
    int main()
    {
    code
    // call a function
    func1();
    //...etc
    return 0;
    }
    [/code]
    [/purple]


  • : [b][red]This message was edited by Extrasolar at 2004-1-15 15:33:46[/red][/b][hr]
    : [purple]
    : It is because you are declaring your functions INSIDE of main. remove the ; at the end of the function i.e func1(); should be func1() and place them OUTSIDE of main before int main().
    :
    : [code]
    : you have:
    :
    : int main()
    : {
    : blah blah blah
    : func1();
    : {
    : code
    : }
    : func2();
    : {
    : code
    : }
    : func3{};
    : {
    : code
    : }
    : ...etc
    : return 0;
    : }
    :
    : You should have:
    :
    : func1()
    : {
    : code
    : }
    : func2()
    : {
    : code
    : }
    : func3()
    : {
    : code
    : }
    : int main()
    : {
    : code
    : // call a function
    : func1();
    : //...etc
    : return 0;
    : }
    : [/code]
    : [/purple]
    :
    :
    :
    thank you for your help!! both of you, the last reply cleared it up to me..

    thanks again, you're da best!
    the program worx now!

  • : : [b][red]This message was edited by Extrasolar at 2004-1-15 15:33:46[/red][/b][hr]
    : : [purple]
    : : It is because you are declaring your functions INSIDE of main. remove the ; at the end of the function i.e func1(); should be func1() and place them OUTSIDE of main before int main().
    : :
    : : [code]
    : : you have:
    : :
    : : int main()
    : : {
    : : blah blah blah
    : : func1();
    : : {
    : : code
    : : }
    : : func2();
    : : {
    : : code
    : : }
    : : func3{};
    : : {
    : : code
    : : }
    : : ...etc
    : : return 0;
    : : }
    : :
    : : You should have:
    : :
    : : func1()
    : : {
    : : code
    : : }
    : : func2()
    : : {
    : : code
    : : }
    : : func3()
    : : {
    : : code
    : : }
    : : int main()
    : : {
    : : code
    : : // call a function
    : : func1();
    : : //...etc
    : : return 0;
    : : }
    : : [/code]
    : : [/purple]
    : :
    : :
    : :
    : thank you for your help!! both of you, the last reply cleared it up to me..
    :
    : thanks again, you're da best!
    : the program worx now!
    :
    :
    oh, here's the code, enjoy the caculator!
    [code]
    /********************************
    /Author: Amer Adeeb Al-Sadiq *
    /E-mail: nectron101@hotmail.com *
    /Project: Geometric Calculator. *
    /Version: 1.0 *
    /Date: 15/01/2004 *
    /*******************************/

    #include
    #include
    using namespace std;
    int one(), two(), three(), four(), five();
    double six(), seven(), eight();
    int nine(), ten();
    int main()
    {
    int selec, width, length, recpri, recar, squpri, squar, tripri;
    int parpri, parar, liseg, liseg2, liseg3, hight, base;
    int radius, side;
    double circir, cirar, triar;
    cout << " Geometric Calculator" << endl;
    cout << " Version 1.0 " << endl << endl;
    cout << " By: Amer Al-Sadiq" << endl;
    cout << " nectron101@hotmail.com" << endl << endl << endl;
    cout << "Please choose an operation:" << endl << endl;
    cout << "1.Reactangle Perimeter." << " 2.Rectangle Area." << endl << endl;
    cout << "3.Square Perimeter." << " 4.Square Area." << endl << endl;
    cout << "5.Triangle Perimeter." << " 6.Triangle Area." << endl << endl;
    cout << "7.Circle Circumference." << " 8.Circle Area." << endl << endl;
    cout << "9.Parallelogram Perimeter." << " 10.Parallelogram Area." << endl << endl << endl;
    cout << "Enter operation number:";
    cin >> selec;

    switch (selec)
    {
    case 1: one();
    break;

    case 2: two();
    break;

    case 3: three();
    break;

    case 4: four();
    break;

    case 5: five();
    break;

    case 6: six();
    break;

    case 7: seven();
    break;

    case 8: eight();
    break;

    case 9: nine();
    break;

    case 10: ten();
    break;

    default:
    cout << "Error! unknown input, quitting..." << endl;
    break;
    }

    system ("pause");
    return 0;
    }

    int one()
    {
    int length, width, recpri;
    cout << "Please enter length:";
    cin >> length;
    cout << "Please enter width:";
    cin >> width;
    recpri = (2*length)+(2*width);
    cout << "
    Rectangle's Perimeter = " << recpri << endl;
    return 0;
    }

    int two()
    {
    int length, width, recar;
    cout << "Please enter length:";
    cin >> length;
    cout << "
    Please enter width:";
    cin >> width;
    recar = (length*width);
    cout << "
    Rectangle's Area = " << recar << endl;
    return 0;
    }

    int three()
    {
    int liseg, squpri;
    cout << "Please enter line segment:";
    cin >> liseg;
    squpri = (4*liseg);
    cout << "
    Square's Perimeter = " << squpri << endl;
    return 0;
    }


    int four()
    {
    int liseg, squar;
    cout << "Please line segment:";
    cin >> liseg;
    squar = (liseg*liseg);
    cout << "
    Square's Area = " << squar << endl;
    return 0;
    }

    int five()
    {
    int liseg, liseg2, liseg3, tripri;
    cout << "Please enter first line segment:";
    cin >> liseg;
    cout << "Please enter second line segment:";
    cin >> liseg2;
    cout << "Please enter third line segment:";
    cin >> liseg3;
    tripri = (liseg+liseg2+liseg3);
    cout << "
    Triangle's Perimeter = " << tripri << endl;
    return 0;
    }

    double six()
    {
    int hight, base;
    double triar;
    cout << "Please enter hight:";
    cin >> hight;
    cout << "
    Please enter base:";
    cin >> base;
    triar = (0.5*hight*base);
    cout << "
    Triangle's Area = " << triar << endl;
    return 0;
    }

    double seven()
    {
    int radius;
    double circir;
    cout << "Please enter radius:";
    cin >> radius;
    circir = (3.1415926*radius);
    cout << "
    Circle's Circumference = " << circir << endl;
    return 0;
    }

    double eight()
    {
    int radius;
    double cirar;
    cout << "Please enter radius:";
    cin >> radius;
    cirar = (3.1415926*radius*radius);
    cout << "
    Circle's Area = " << cirar << endl;
    return 0;
    }

    int nine()
    {
    int base, side, parpri;
    cout << "Please enter base:";
    cin >> base;
    cout << "Please enter side:";
    cin >> side;
    parpri = ((2*base)+(2*side));
    cout << "
    Parallelogram's Perimeter = " << parpri << endl;
    return 0;
    }

    int ten()
    {
    int hight, base, parar;
    cout << "Please enter hight:";
    cin >> hight;
    cout << "
    Please enter base:";
    cin >> base;
    parar = (hight*base);
    cout << "
    Parallelogram's Area = " << parar << endl;
    return 0;
    }
    [/code]

  • [purple]
    Glad you got it working. :) Word of advice, your function names should really reflect what they are doing. Thus "int one()" should be something like "int RectanglePerimeter()"..etc. Makes it a lot clearer. :)
    [/purple]
  • : [purple]
    : Glad you got it working. :) Word of advice, your function names should really reflect what they are doing. Thus "int one()" should be something like "int RectanglePerimeter()"..etc. Makes it a lot clearer. :)
    : [/purple]
    :
    what do you think of that as my first C++ program?
    please rate it out of 5 "remember it's the first one"


    please visit my website: http://www.amer101.cjb.net

  • : : [purple]
    : : Glad you got it working. :) Word of advice, your function names should really reflect what they are doing. Thus "int one()" should be something like "int RectanglePerimeter()"..etc. Makes it a lot clearer. :)
    : : [/purple]
    : :
    : what do you think of that as my first C++ program?
    : please rate it out of 5 "remember it's the first one"
    Pretty good to say it's your first try at it - at least you did most of it then posted your problems, whereas I'm pretty sure some people show up saying "I don't know what to do" and haven't tried anything. :-) The advice about using meaningful names for functions is good - also always use meaningful names for variables too, and indent your code correctly, and use plenty of comments to say what is going on. The only other thing I'd say is to make sure if you have compile errors that you post them with your question, as it can be very hard to help if you don't.

    Ratings out of 5 don't mean much - I figure advice and pointers on what is good are better. But, well...maybe between 3/5 and 4/5.

    : please visit my website: http://www.amer101.cjb.net
    Awww...your cat is so cute! :-) Yeah, I'm a cat lover.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • To add to what the others suggested, you *might* consider creating const menu variables in place of printing each one.

    Your prototypes seem a bit cluttered, and you may also *think* about declaring the parameter list explicitly. int someFunc(void)

    You declare variables in main, yet you declare them again in your functions/procedures. Along the same lines, double six() is expecting a double return value, but you're returning an integer. Not all bad in your usage within this program, but the habit *could* lead you to problems down the road.

    You can also compact a few of these functions by passing in arguments.

    [code][size=3]double calcRectangle(double, double, int code=0);

    result = calcRectangle(width, length, 0);
    result = calcRectangle(width, length, 1);

    ...
    main
    ...

    double calcRectangle(double w, double l, int code)
    {
    double temp = 0.0;

    if(code == 0)
    temp = (2 * w) + (2 * l);
    if(code == 1)
    temp = (w * l);

    return (temp);
    }[/size][/code]

    I'd suggest that you declare a few variables in main, get the input there, validate the input is good, pass the input to your functions, and then get the result for outputting.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories