Could someone correct this an explain why I get this error. main.cpp: In functio
ID: 3884558 • Letter: C
Question
Could someone correct this an explain why I get this error.
main.cpp: In function ‘int main(int, char**)’:
main.cpp:29:34: error: invalid conversion from ‘double*’ to ‘char’ [-fpermissive]
getInput(&Number1, &opt, &Number2);
^
main.cpp:29:34: error: cannot convert ‘char*’ to ‘double’ for argument ‘2’ to ‘void getInput(char, double, double)’
Code Snippet
#include <cstdlib>
#include <iostream>
using namespace std;
/*
*
*/
double add(double Number1, double Number2);
double subtract(double Number1, double Number2);
double divide(double Number1, double Number2);
double multiply(double Number1, double Number2);
void getInput(char opt, double Number1, double Number2);
int main(int argc, char** argv)
{
double Number1; double Number2; char opt;
int exit = 1;
while(1)
{
getInput(&Number1, &opt, &Number2);
if(opt == '+')
{
cout<<"Add of two doubles is "<<add(Number1,Number2)<<endl;
}
else if(opt == '-')
{
cout<<"Subtract of two doubles is "<<subtract(Number1,Number2)<<endl;
}
else if(opt == '*')
{
cout<<"Multiply of two doubles is "<<multiply(Number1,Number2)<<endl;
}
else if(opt == '/')
{
cout<<"Divide of two doubles is "<<divide(Number1,Number2)<<endl;
}
else
{
cout << "Error! operator is not correct";
}
39,0-1 Top
Explanation / Answer
In the function int main(int argc, char** argv)
you are calling the function getInput with arguments as references
But in the declaration of getInput() the arguments are not of pointer type. Also the order of arguments donot match.
The correct declaration would be getInput(double* num1, char* op,double*num2).