I am new to c++ and I am wodering how to properly define functions?
Right now I am receiving the following errors:
Severity Code Description Project File Line Suppression State
Error (active) E0065 expected a ';' ConsoleMath D:\C++\ConsoleMath\ConsoleMath\ConsoleMath.cpp 18
Error C2601 'Basic': local function definitions are illegal ConsoleMath D:\C++\ConsoleMath\ConsoleMath\ConsoleMath.cpp 18
I've tried to place the function outside of "int main ()", but there was no effect...
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
// Initialization
string command;
bool loop = true;
float number1 = 0, number2 = 0;
// Start-up
cout << "Welcome to Console Math v1.0.0\n\nThis software can be used for a variety of mathematical operations.\n\nFor list of commands; type \"help\"\nTo exit the program; type \"exit\"\n"
<< endl;
// Commands
void Basic()
{
cout << " >";
// Code here
}
// Main software loop
while (loop == true)
{
cout << "> ";
cin >> command;
cout << endl
<< endl;
if (command == "help")
{
cout << "Command layout (\">\" symbolizes new input after entering the previous one):\n> DatabaseName > operationName > detail name\n\n> basic\n > add\n > subtract\n > multiply\n > divide\n> advanced\n > potentiation\n > squareRoot\n > findPrimeNumbers\n > logarithm\n > factorial\n > function\n > intersection\n > linear-linear\n > linear-parabola\n > geometry\n > rectangle\n > perimeter\n > area\n > visualize\n > triangle\n > perimeter\n > area\n > basic\n > hemmonDefinedS\n > hemmonDefineS\n > coordinate\n > height\n > circle\n > area\n > circumference\n> trigonometry\n > sin\n > cos\n > tg\n > ctg\n> degrees\n > add\n > subtract\n > multiply\n > divide\n > other\n > random\n > randomRange";
}
else if (command == "basic")
{
Basic();
}
else if (command == "exit")
{
loop = false;
}
else
{
cout << "\"" << command << "\" is not a valid command. If you're having trouble please type \"help\"";
}
cout << endl
<< endl;
}
return 0;
}
Is there any way to fix this?
Update: Here is the code when I place the function outside of "main()"... Is there a way to call it from "main()".
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;
void Basic()
{
cout << " >";
// Code here
}
int main()
{
// Initialization
string command;
bool loop = true;
float number1 = 0, number2 = 0;
// Start-up
cout << "Welcome to Console Math v1.0.0\n\nThis software can be used for a variety of mathematical operations.\n\nFor list of commands; type \"help\"\nTo exit the program; type \"exit\"\n"
<< endl;
// Commands
// Main software loop
while (loop == true)
{
cout << "> ";
cin >> command;
cout << endl
<< endl;
if (command == "help")
{
cout << "Command layout (\">\" symbolizes new input after entering the previous one):\n> DatabaseName > operationName > detail name\n\n> basic\n > add\n > subtract\n > multiply\n > divide\n> advanced\n > potentiation\n > squareRoot\n > findPrimeNumbers\n > logarithm\n > factorial\n > function\n > intersection\n > linear-linear\n > linear-parabola\n > geometry\n > rectangle\n > perimeter\n > area\n > visualize\n > triangle\n > perimeter\n > area\n > basic\n > hemmonDefinedS\n > hemmonDefineS\n > coordinate\n > height\n > circle\n > area\n > circumference\n> trigonometry\n > sin\n > cos\n > tg\n > ctg\n> degrees\n > add\n > subtract\n > multiply\n > divide\n > other\n > random\n > randomRange";
}
else if (command == "basic")
{
Basic();
}
else if (command == "exit")
{
loop = false;
}
else
{
cout << "\"" << command << "\" is not a valid command. If you're having trouble please type \"help\"";
}
cout << endl
<< endl;
}
return 0;
}