E
eli m
Any idea on how i could make this code better?
My code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int run = 0;
string function, mathop;
cout << "Type in help for a list of functions\n";
//Start main loop
while (run == 0)
{
cout << "Type in a function:";
cin >> function;
//Math function
if (function == "math")
{
int mathloop;
mathloop = 0;
//Start while loop for math function
while (mathloop == 0)
{
cout << "What math operation do you want to use?";
cin >> mathop;
// Multiplication Math Function
if (mathop == "multiplication")
{
int mfirstnum, msecondnum, ans;
cout << "Type in your first number:";
cin >> mfirstnum;
cout << "Multiply your first number by:";
cin >> msecondnum;
ans = mfirstnum * msecondnum;
cout << ans << "\n";
}
//Break out of mathloop if main is entered
else if (mathop == "main")
{
mathloop = 1;
}
}
}
}
}
My code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int run = 0;
string function, mathop;
cout << "Type in help for a list of functions\n";
//Start main loop
while (run == 0)
{
cout << "Type in a function:";
cin >> function;
//Math function
if (function == "math")
{
int mathloop;
mathloop = 0;
//Start while loop for math function
while (mathloop == 0)
{
cout << "What math operation do you want to use?";
cin >> mathop;
// Multiplication Math Function
if (mathop == "multiplication")
{
int mfirstnum, msecondnum, ans;
cout << "Type in your first number:";
cin >> mfirstnum;
cout << "Multiply your first number by:";
cin >> msecondnum;
ans = mfirstnum * msecondnum;
cout << ans << "\n";
}
//Break out of mathloop if main is entered
else if (mathop == "main")
{
mathloop = 1;
}
}
}
}
}