Thread: please help

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    3

    please help

    undefinedundefinedundefined
    [tag]
    i've been trying to write a program which allows the user to choose the math function for an equation but i don't know how to define it in the program or anything, i've got a simple version here but it doesn't work- could anyone give me any advice cheers
    [\tag]
    [code]
    #include <iostream.h>
    #include <math.h>
    #include <iomanip>



    double x, y, z, d;
    char fx;
    main()
    {
    cout<< "enter a func for x";
    cin>>fx;
    for (x=0; x<6; x++)
    {
    y=fx;
    cout<<setw(6)<<x<<setw(6)<<y<<endl;
    }
    cin>> d;
    return 0;
    }
    [\code]

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Welcome to the board.

    Nice try with the code tags, but it's a / instead of a \ before the word code that does the magic.

    Often this type of a program is set up with a menu and a switch:

    //menu
    int choice;
    cout << "enter # of selection from choices below" << endl;
    cout << "1) +" << endl;
    cout << "2) -" << endl;
    //etc
    cin >> choice;

    or

    char choice;
    cout << "enter the sign of the arithmetic function you wish to do" << endl;
    cin >> choice;

    Then use choice as the conditional of the switch:
    Code:
    switch(choice)
    {
      case 1:
    	 //do adding or call add function
    	 break;
      case 2:
    	 //do subtraction or call subtraction function
    	 break;
      //etc
    }
     
    or 
    switch(choice)
    {
       case '+':
    	 //do adding or call add function
    	 break;
       case '-':
    	 //do subtraction or call subtraction function
    	 break;
       //etc
    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Or you could explore even more ways of messing up the code tags

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    3
    [tag]thanks, but i should have been more specific i'm looking for ways to input functions like sin(x) and x^2, [/tag]

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    3

    Talking

    i give up on the tags too

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, it's the same thing; have an option for 'sin' (option #4 or something), and in your switch block, do 'sin'. The functions you're looking for are, sin(x) etc. and pow(x,2), which are defined in <cmath>.

    Just out of curiosity though, what are [tag] and [/tag] supposed to be? lol
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed