hi, i wanted to find the factorial with the same problem that I had the previous time:
here's the code that I wrote, so how can i find the factorial and display it to the user?
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(void)
{
string input ;
int a, b;
char Doagain;
do{
cout << "What would you like to do? (Add, Subtract, Multiply, Divide) Or if you would like to do something else, type other. ";
cin >> input;
if (input == "other")
{
char inputtoo;
cout << "Would you like to find a factorial? (Y/N) ";
cin >> inputtoo;
switch (inputtoo)
{
case 'Y':
{
cout << "Input the number you would like to find the factorial for: ";
cin >> a;
for(int b; b=1; b--);
b = a;
cout << "The factorial of is" << a << endl;
}
case 'N':
cout << "Why did you select this? " << endl;
}
}
else if (input == "Add")
{
cout << "Enter a value: ";
cin >> a;
cout << "Enter another value: ";
cin >> b;
cout << "The sum of the numbers is " << a + b << endl;
}
else if (input == "Subtract")
{
cout << "Enter a value: ";
cin >> a;
cout << "Enter another value: ";
cin >> b;
cout << "The difference of the two numbers is " << a - b << endl;
}
else if (input == "Multiply")
{
cout << "Enter a value: ";
cin >> a;
cout << "Enter another value: ";
cin >> b;
cout << "The product of the two numbers is " << a * b << endl;
}
else if (input == "Divide")
{
cout << "Enter a value: ";
cin >> a;
cout << "Enter another value: ";
cin >> b;
cout << "The quotient of the two numbers is " << a / b << endl;
cout << "And the remainder is " << a % b << endl;
}
cout << "Would you like to do it again? (y/n) ";
cin >> Doagain;
}while (Doagain == 'Y' || Doagain == 'y');
return 0;
}
so how can i change this code so that the factorial could also be found? for the for loop here it's showing an error :limac@limac-kubuntu:~/Desktop$ g++ -o math math.cpp
math.cpp: In function ‘int main()’:
math.cpp:31: warning: name lookup of ‘b’ changed
math.cpp:10: warning: matches this ‘b’ under ISO standard rules
math.cpp:30: warning: matches this ‘b’ under old rules
any help would be very appreciated!
Thx