-
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]
-
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
}
-
Or you could explore even more ways of messing up the code tags :rolleyes:
-
[tag]thanks, but i should have been more specific i'm looking for ways to input functions like sin(x) and x^2, [/tag]
-
i give up on the tags too
-
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 :confused: