how do i go about this question in regards to for and while loops?
the user to enter two numbers and the operation to be performed , and then we display the answer . If the user type ‘A’ or ‘a’ that’s addition If the user type ‘S’ or ‘s’ that’s subtraction If the user type ‘M’ or ‘m’ that’s multiplication If the user type ‘D’ or ‘d’ that’s division
An Example of running : Enter first number : 5 Enter second number : -6 Enter the operation to be performed: M The Answer is -30
2. Modify the previous program so that it avoid dividing by zero, if the second number is a zero it will show , Division by zero is impossible
3. Modify your program so it will use repetition structure and ask the user to enter the operations and numbers repeatedly and stop when the user enter x for the operation.
The program must ask user do you want to continue Y or N . If user enter n the program must stop
hi kemort was a bit busy with work. this is what i came up with the thing is when its calculating the answers are wrong.............................
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
int firstnumber, secondnumber;
int Total,multiply,divide;
int M = firstnumber * secondnumber;
int D = firstnumber / secondnumber;
char maths = ' ';
char yesno;
cout<<"Please enter M for Multiplication or D for Division and press Enter. ";
cin >> maths ;
maths = toupper(maths);
cout << endl << maths << endl;
cout << "Please enter the first number: ";
cin >> firstnumber;
cout << "Please enter the second number : ";
cin >> secondnumber;
if(maths == 'M') {
cout << "the multiplication of the two numbers is:" <<M << endl;
}
else if (maths == 'D') {
cout << "the division of the two numbers is:" <<D << endl;
while (secondnumber == 0)
{
cout << "Sorry, you cannot divide by (0)";
cin >> firstnumber;
cout << "please enter the second number you would like to divide by: ";
cin >> secondnumber;
}
cout<<"Do you want to continue enter Y or N to stop: ";
cin>>yesno;
yesno = tolower(yesno);
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
int firstnumber, secondnumber;
int Total,multiply,divide;
int M = firstnumber * secondnumber;
int D = firstnumber / secondnumber;
char maths = ' ';
char yesno;
do
{
cout<<"Please enter M for Multiplication or D for Division and press Enter. ";
cin >> maths ;
maths = toupper(maths);
cout << endl << maths << endl;
cout << "Please enter the first number: ";
cin >> firstnumber;
cout << "Please enter the second number: ";
cin >> secondnumber;
while (secondnumber == 0)
{
cout << "Sorry, you cannot divide by (0)" << endl;
cout << "Please enter the first number: ";
cin >> firstnumber;
cout << "please enter the second number you would like to divide by: ";
cin >> secondnumber;
}
if(maths == 'M')
{
cout << "the multiplication of the two numbers is: " << firstnumber * secondnumber << endl;
}
elseif (maths == 'D')
{
cout << "the division of the two numbers is:" << firstnumber / secondnumber << endl;
}
cout << "Do you want to continue enter Y or N to stop: ";
cin >> yesno;
yesno = toupper(yesno);
}while (yesno == 'Y');
// system ("pause");
return 0;
}