Cannot convert double for argument 1 to double [on hold]
up vote
-2
down vote
favorite
I'm a beginner trying to learn c++ and my code won't compile. I've looked through other questions that got an error like mine, but still am not sure how to go on about this. I am getting error saying "cannot convert double for argument 1 to double timer(double, double, double)". Also, I am using the return value from range function to get the return value of timer function, and I'm not sure if i have to do something else in order for that to happen. The equations are supposed to be in separate functions, except the one under while loop.
#include <iomanip>
#include <math.h>
#include <iostream>
using namespace std;
const double g_m=32.0;
double thetaDegrees, sph, T; //sph= speed pr sec
double sec, t;
double x, y, z;
double range(double sph, double const g_m, double thetaDegrees) //
{
return (pow(sph,2.0))/g_m*sin(2.0*thetaDegrees);
}
double timer(double range, double thetaDegrees, double sph)
{
return range/sph*cos(thetaDegrees);
}
double distance(double sph, double sec, double thetaDegrees)
{
return sph*sec*cos(thetaDegrees);
}
double height(double sph, double thetaDegrees, double sec, double z)
{
return ((sph*sec*sin(thetaDegrees))-(1.0/2.0*pow(sec,2.0))+z);
}
int main()
{
int choice;
bool stuff = true;
while (stuff != false){
cout << " Please choose if you want to enter speed in KPH or MPH. n ";
cout << " 1 KPH.n";
cout << " 2 MPH.n";
cin >> choice;
switch (choice)
{
case 1:
{
cout << "You chose KPH n";
cout << "Enter angle(degrees) and velocity(kph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<< range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<< timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 2:
{
cout << "You chose MPH n";
cout << "Enter angle(degrees) and velocity(mph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<<range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 3:
{
cout << "End n";
stuff = false;
}
break;
}
}
return 0;
}
c++
New contributor
put on hold as off-topic by πάντα ῥεῖ, Silvio Mayolo, Hovercraft Full Of Eels, S.M., xaxxon Nov 5 at 2:25
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Silvio Mayolo, xaxxon
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – πάντα ῥεῖ, Hovercraft Full Of Eels, S.M.
If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
up vote
-2
down vote
favorite
I'm a beginner trying to learn c++ and my code won't compile. I've looked through other questions that got an error like mine, but still am not sure how to go on about this. I am getting error saying "cannot convert double for argument 1 to double timer(double, double, double)". Also, I am using the return value from range function to get the return value of timer function, and I'm not sure if i have to do something else in order for that to happen. The equations are supposed to be in separate functions, except the one under while loop.
#include <iomanip>
#include <math.h>
#include <iostream>
using namespace std;
const double g_m=32.0;
double thetaDegrees, sph, T; //sph= speed pr sec
double sec, t;
double x, y, z;
double range(double sph, double const g_m, double thetaDegrees) //
{
return (pow(sph,2.0))/g_m*sin(2.0*thetaDegrees);
}
double timer(double range, double thetaDegrees, double sph)
{
return range/sph*cos(thetaDegrees);
}
double distance(double sph, double sec, double thetaDegrees)
{
return sph*sec*cos(thetaDegrees);
}
double height(double sph, double thetaDegrees, double sec, double z)
{
return ((sph*sec*sin(thetaDegrees))-(1.0/2.0*pow(sec,2.0))+z);
}
int main()
{
int choice;
bool stuff = true;
while (stuff != false){
cout << " Please choose if you want to enter speed in KPH or MPH. n ";
cout << " 1 KPH.n";
cout << " 2 MPH.n";
cin >> choice;
switch (choice)
{
case 1:
{
cout << "You chose KPH n";
cout << "Enter angle(degrees) and velocity(kph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<< range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<< timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 2:
{
cout << "You chose MPH n";
cout << "Enter angle(degrees) and velocity(mph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<<range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 3:
{
cout << "End n";
stuff = false;
}
break;
}
}
return 0;
}
c++
New contributor
put on hold as off-topic by πάντα ῥεῖ, Silvio Mayolo, Hovercraft Full Of Eels, S.M., xaxxon Nov 5 at 2:25
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Silvio Mayolo, xaxxon
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – πάντα ῥεῖ, Hovercraft Full Of Eels, S.M.
If this question can be reworded to fit the rules in the help center, please edit the question.
1
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()
– drescherjm
Nov 5 at 2:16
1
You are not using the return value fromrange
. You're printing it to the screen, discarding it, and then trying to pass therange
function.
– Silvio Mayolo
Nov 5 at 2:17
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24
|
show 2 more comments
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I'm a beginner trying to learn c++ and my code won't compile. I've looked through other questions that got an error like mine, but still am not sure how to go on about this. I am getting error saying "cannot convert double for argument 1 to double timer(double, double, double)". Also, I am using the return value from range function to get the return value of timer function, and I'm not sure if i have to do something else in order for that to happen. The equations are supposed to be in separate functions, except the one under while loop.
#include <iomanip>
#include <math.h>
#include <iostream>
using namespace std;
const double g_m=32.0;
double thetaDegrees, sph, T; //sph= speed pr sec
double sec, t;
double x, y, z;
double range(double sph, double const g_m, double thetaDegrees) //
{
return (pow(sph,2.0))/g_m*sin(2.0*thetaDegrees);
}
double timer(double range, double thetaDegrees, double sph)
{
return range/sph*cos(thetaDegrees);
}
double distance(double sph, double sec, double thetaDegrees)
{
return sph*sec*cos(thetaDegrees);
}
double height(double sph, double thetaDegrees, double sec, double z)
{
return ((sph*sec*sin(thetaDegrees))-(1.0/2.0*pow(sec,2.0))+z);
}
int main()
{
int choice;
bool stuff = true;
while (stuff != false){
cout << " Please choose if you want to enter speed in KPH or MPH. n ";
cout << " 1 KPH.n";
cout << " 2 MPH.n";
cin >> choice;
switch (choice)
{
case 1:
{
cout << "You chose KPH n";
cout << "Enter angle(degrees) and velocity(kph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<< range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<< timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 2:
{
cout << "You chose MPH n";
cout << "Enter angle(degrees) and velocity(mph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<<range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 3:
{
cout << "End n";
stuff = false;
}
break;
}
}
return 0;
}
c++
New contributor
I'm a beginner trying to learn c++ and my code won't compile. I've looked through other questions that got an error like mine, but still am not sure how to go on about this. I am getting error saying "cannot convert double for argument 1 to double timer(double, double, double)". Also, I am using the return value from range function to get the return value of timer function, and I'm not sure if i have to do something else in order for that to happen. The equations are supposed to be in separate functions, except the one under while loop.
#include <iomanip>
#include <math.h>
#include <iostream>
using namespace std;
const double g_m=32.0;
double thetaDegrees, sph, T; //sph= speed pr sec
double sec, t;
double x, y, z;
double range(double sph, double const g_m, double thetaDegrees) //
{
return (pow(sph,2.0))/g_m*sin(2.0*thetaDegrees);
}
double timer(double range, double thetaDegrees, double sph)
{
return range/sph*cos(thetaDegrees);
}
double distance(double sph, double sec, double thetaDegrees)
{
return sph*sec*cos(thetaDegrees);
}
double height(double sph, double thetaDegrees, double sec, double z)
{
return ((sph*sec*sin(thetaDegrees))-(1.0/2.0*pow(sec,2.0))+z);
}
int main()
{
int choice;
bool stuff = true;
while (stuff != false){
cout << " Please choose if you want to enter speed in KPH or MPH. n ";
cout << " 1 KPH.n";
cout << " 2 MPH.n";
cin >> choice;
switch (choice)
{
case 1:
{
cout << "You chose KPH n";
cout << "Enter angle(degrees) and velocity(kph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<< range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<< timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 2:
{
cout << "You chose MPH n";
cout << "Enter angle(degrees) and velocity(mph) n";
cin >> thetaDegrees >> sph;
if ( sph==0 )
{
cin.clear();
cin.ignore(512, 'n');
cout<< "Bad data n";
}
else
{
if(thetaDegrees<0.0)
{
cerr<<"degrees< error! n";
}
else
{
if(thetaDegrees>90)
{
cerr<<"degrees< error! n";
}
else
{
cout<<range(sph, g_m, thetaDegrees)<<"feet(Range)n";
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
while(sec<=timer(range, thetaDegrees, sph))
{
double sec = sec+ (timer(range, thetaDegrees, sph)/50.0);
cout<<fixed;
cout<<setprecision(3);
cout<<left<<setw(25)<<"Total Flight Time(secs)";
cout<<left<<setw(25)<<"Horizontal Distance(ft)";
cout<<left<<setw(25)<<"Height(ft)";
cout<< "n"<<endl;
cout<<left<<setw(25)<<sec;
cout<<left<<setw(25)<<x;
cout<<left<<setw(25)<<y;
cout<< "n"<<endl;
}
}
}
}
}
break;
case 3:
{
cout << "End n";
stuff = false;
}
break;
}
}
return 0;
}
c++
c++
New contributor
New contributor
New contributor
asked Nov 5 at 2:13
SH257
1
1
New contributor
New contributor
put on hold as off-topic by πάντα ῥεῖ, Silvio Mayolo, Hovercraft Full Of Eels, S.M., xaxxon Nov 5 at 2:25
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Silvio Mayolo, xaxxon
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – πάντα ῥεῖ, Hovercraft Full Of Eels, S.M.
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by πάντα ῥεῖ, Silvio Mayolo, Hovercraft Full Of Eels, S.M., xaxxon Nov 5 at 2:25
This question appears to be off-topic. The users who voted to close gave these specific reasons:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Silvio Mayolo, xaxxon
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – πάντα ῥεῖ, Hovercraft Full Of Eels, S.M.
If this question can be reworded to fit the rules in the help center, please edit the question.
1
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()
– drescherjm
Nov 5 at 2:16
1
You are not using the return value fromrange
. You're printing it to the screen, discarding it, and then trying to pass therange
function.
– Silvio Mayolo
Nov 5 at 2:17
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24
|
show 2 more comments
1
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()
– drescherjm
Nov 5 at 2:16
1
You are not using the return value fromrange
. You're printing it to the screen, discarding it, and then trying to pass therange
function.
– Silvio Mayolo
Nov 5 at 2:17
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24
1
1
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()– drescherjm
Nov 5 at 2:16
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()– drescherjm
Nov 5 at 2:16
1
1
You are not using the return value from
range
. You're printing it to the screen, discarding it, and then trying to pass the range
function.– Silvio Mayolo
Nov 5 at 2:17
You are not using the return value from
range
. You're printing it to the screen, discarding it, and then trying to pass the range
function.– Silvio Mayolo
Nov 5 at 2:17
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
cout<<timer(range, thetaDegrees, sph)<<"secs in airn";
range is a function. You forgot the ()– drescherjm
Nov 5 at 2:16
1
You are not using the return value from
range
. You're printing it to the screen, discarding it, and then trying to pass therange
function.– Silvio Mayolo
Nov 5 at 2:17
BTW, before anyone asks the question was likely downvoted because there is way way too much code to serve as a good Q and A. Remember the main purpose of a question is to help readers in the future with the same problem. I did not downvote however.
– drescherjm
Nov 5 at 2:18
A solution to this problem is to store the value returned in a double variable. Then on the next line use cout to print. And on the 3rd line call your timer()
– drescherjm
Nov 5 at 2:24
make sure to post a minimal example that reproduces your issue, as described here: Minimal, Complete, and Verifiable example
– xaxxon
Nov 5 at 2:24