Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Trouble With C++ Calculator, Exponents.?
Wow, I thought I had already posted this... But I guess not. Ok, so I made a revised calc, but it can't do exponents. Help, it just pauses, and sits there stupid.
Heres the source:
#include <iostream>
#include <string>
using namespace std;
double add(double, double);
double subtract(double, double);
double multiply(double, double);
double divide(double, double);
double expo(long long, double);
double tryagain();
double enternew();
string put1();
string put2();
string put3();
string put4();
string yn();
void do1();
void aaa();
int main()
{
aaa();
}
double add(double a, double b)
{
double c=(a+b);
return (c);
}
double subtract(double a, double b)
{
double c=(a-b);
return (c);
}
double multiply(double a, double b)
{
double c=(a*b);
return (c);
}
double divide(double a, double b)
{
double c=(a/b);
return (c);
}
double expo(double a, double b)
{
double x=1;
double q=a;
double yes;
while(x<b)
{
yes=(a+q);
}
return (yes);
}
string put1()
{
string a="Please input the first number.\n";
return (a);
}
string put2()
{
string a="Please input the second number.\n";
return (a);
}
string put3()
{
string a="Please try again.\n";
return (a);
}
string put4()
{
string a="Would you like to go again?\n";
return (a);
}
string yn()
{
string c;
cin >> c;
string a=c;
return (a);
}
void do1()
{
string q=put4();
cout << q;
string std=yn();
string a="yes";
string b="no";
if(std==a)
{
aaa();
}
if(std==b)
{
cout << "Ok then, guess there's always next time, eh?\n";
}
}
void aaa()
{
double a, b, x, y, z;
string c="add";
string d="subtract";
string e="multiply";
string f="divide";
string g="expo";
string h, i, j, k, l, m, n, o, p, q, r;
cout << "Please enter what you want to do.\n";
cin >> h;
if(h==c)
{
i=put1();
cout << i;
cin >> a;
i=put2();
cout << i;
cin >> b;
z=add(a,b);
cout << z << "\n";
}
if(h==d)
{
i=put1();
cout << i;
cin >> a;
i=put2();
cout << i;
cin >> b;
z=subtract(a,b);
cout << z << "\n";
}
if(h==e)
{
i=put1();
cout << i;
cin >> a;
i=put2();
cout << i;
cin >> b;
z=multiply(a,b);
cout << z << "\n";
}
if(h==f)
{
i=put1();
cout << i;
cin >> a;
i=put2();
cout << i;
cin >> b;
z=divide(a,b);
cout << z << "\n";
}
if(h==g)
{
i=put1();
cout << i;
cin >> a;
i=put2();
cout << i;
cin >> b;
z=expo(a,b);
cout << z << "\n";
}
if(h!=c && h!=d && h!=e && h!=f && h!=g)
{
cout << "Please try again, the statement you entered is invalid.\n";
aaa();
}
do1();
}
Thanks. Hope you can help.
3 Answers
- sspade30Lv 59 years agoFavorite Answer
you never increment x in your loop, so it will loop forever.
Once you do that, you'll get the wrong answer. You will always get either undefined number, or 2*a, since yes isn't initialized and it gets set to a+q, and the values of a and q never change.
Keep trying.
- azizLv 44 years ago
for ? x?3x dx, you are able to desire to alter it to ?3 ? x*x^(a million/2) = ?3 ? x^(3/2) = ?3 [(2/5)x^(5/2)] + C so A once you have an analogous base, consisting of x, you upload the exponents so (x^2)*(x^4)=x^6 for ƒ(x)=sin²x, locate f???(x) exchange ƒ(x)=sin²x to ƒ(x)=[sin(x)]² so, by using chain rule, f'(x)=2sin(x)*cos(x) now for f''(x) you are able to could desire to apply the product rule so u=2sinx, u'=2cosx, v=cosx, v'=-sinx and then f''(x) = u'*v + v'*u = 2cos²x - 2sin²x and now for f'''x, use the product rule lower back.
- Anonymous9 years ago
well, the logic is totally wrong....
2 ^ 3 != 2 + 2 + 2
why not just use pow(x,y) from the math library?