Pass in parameters to each function for the values to use and the functions will return the result. Use a function to read in the numbers involved. These numbers will be doubles. Also write a function that reads in the operator and returns a boolean – true if the operator is valid, false if not valid. This function will have two parameters. First is a string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid.
Can anybody help me to find error, its keep saying me missing declaration ";".
#include <iostream>
cout<< " Enter a number: ";
D1 = ReadDouble ();
do
{
do
{
do
{
cout << "Enter an operator: ";
} while ( (validops, Operator) ==false);
switch (Operator)
{
case'+':
case'-':
case'*':
case'/':
NeedAnotherOperator= false;
break;
case 'C':
case 'c':
D3=0;
cout << "the calculator is cleared now. Please enter a number: ";
D1 = ReadDouble ();
NeedAnotherOperator = true;
break;
case 'X':
case 'x':
exit(0);
break;
default:
cout<< " Invalid Operator. Please enter a valid operator: " << endl;
NeedAnotherOperator=true;
}
}
while (NeedAnotherOperator);
cout << "Enter another number:";
D2 = ReadDouble ();
switch (Operator)
{
case '+':
D3 = D1 + D2;
cout << " Your Result is : " << D3 << endl;
break;
case '-':
D3 = D1 - D2;
cout << " Your Result is : " << D3 << endl;
break;
case '*':
D3 = D1 * D2;
cout << " Your Result is : " << D3 << endl;
break;
case '/':
D3= D1 / D2;
{ if (D2==0)
{
cout << " Can't divide by 0 " << endl;
}
else
{
cout << " Your Result is : "<< D3 << endl;
}
}
break;
default:
break;
You are not understanding something so basic that it is hard to explain. Do you understand what a function definition is? It consists of a return type of a function, the name of the function, and a set of parentheses that may contain parameters. An example:
1 2 3 4
int main()
{
return 0;
}
On line 9, you have void main() but do not have the {} brackets with code following it.