Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
The following program line that starts with "ratio" is supposed to =
5√M/m
where M is maxSpeedRpm and m minSpeedRpm. Please help, I am going cross eyed trying to work this out.
 

 

 

#include <iostream>
#include <cmath>
using namespace std;
int
main0()
{
    int maxSpeedRpm, minSpeedRpm;
    double ratio;
    
    cout << "Enter the maximum speed in revolutions per minute";
    cin >> maxSpeedRpm;
    cout << "Enter the minimum speed in revolutions per minute";
    cin >> minSpeedRpm;
    
    ratio = sqrt((pow(maxSpeedRpm/minSpeedRpm),(1/5)));
 
    cout << "The calculated ratio is" << ratio;
       
    cin.ignore();
    cin.get();
    return 0;
}
Posted 21-Feb-13 20:26pm
Comments
Sergey Alexandrovich Kryukov at 22-Feb-13 1:35am
   
Not a question. Gibberish. Very bad. You did not even report the error message.
—SA
Sarah Trattner at 22-Feb-13 1:38am
   
whatever...I'll wait for someone that can identify the problem.
Sergey Alexandrovich Kryukov at 22-Feb-13 1:42am
   
"Can identify"... Amazing...
Declare all variables you use...
—SA
Sarah Trattner at 22-Feb-13 1:38am
   
15 C:\Dev-Cpp\ratio.cpp no matching function for call to `pow(int)'
Sergey Alexandrovich Kryukov at 22-Feb-13 1:46am
   
Do you at least understand what's power?!!
It's bx, where b is the base, x is exponent. So, there should be two parameters, not one!
See
http://www.cplusplus.com/reference/cmath/pow/
 
—SA
enhzflep at 22-Feb-13 8:14am
   
Additionally, something you may not realize, is that in C/C++, an int divided by an int gives an int. So, 3/10 = 0. If you want to get 0.3, you'll need to declare them as floats or doubles. Also, Code::Blocks is a fairy lightweight IDE that uses MinGW (like DevCPP does) It's much better AND currently maintained. It's well worth the download. :) P.s - Look at Sergey's rep - it's over 10,000 this month! He's probably forgotten more this month than you and I combined have learned in the past year. And you know, technically, he was right insofar as there isn't a question in your initial post. ;) Welcome to the madhouse! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If you intersperse some blanks you can see for yourself why it doesn't compile:
ratio = sqrt( (pow(maxSpeedRpm/minSpeedRpm), (1/5)) );
So you got the parenthese wrong. You probably meant to write:
ratio = sqrt (pow ((maxSpeedRpm/minSpeedRpm), 0.2));
  Permalink  
Comments
Mike M.00 at 22-Feb-13 12:05pm
   
Yes, white space is your friend - computers don't care, but brains see the structure better.
 
HINT to the unseasoned or occasional programmer: Pay close attention to at least the first error message generated by the compiler - make sure you know what it means as it will lead you in the direction of your solution. In this case "no matching function for call to 'pow(int)'" was trying to tell you the compiler could not find a function called 'pow' which took one integer parameter (see hemantrautela's Solution 1).
 
Another trick I like to use to debug complicated math expressions, is to define a series of temporaries and build up the final expression one step at a time. This allows me to see all the intermediary values and it ends up isolating any error messages to exactly and only the offending item, e.g.:
int t1 = maxSpeedRpm/minSpeedRpm; // Here you would see t1 is zero for some data like 5/7, so this needs to be float.
float t2 = pow ( t1, 0.2 ); // And actually pow() needs a double as first argument, but comilers convert it for you.
float t3 = sqrt ( t2 );
A debugger allows you to see each value and understand what's working, what's not.
Mike M.
nv3 at 22-Feb-13 12:35pm
   
Very good points, Mike. I hope the original poster will heed your advice!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

pow() function having two arguments...as below
c++ , cmath
double pow (      double base,      double exponent );
long double pow ( long double base, long double exponent );
      float pow (       float base,       float exponent );
     double pow (      double base,         int exponent );
long double pow ( long double base,         int exponent );
 

Thanks
Asp.Net C# Help Blog[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 265
1 Richard MacCutchan 239
2 OriginalGriff 208
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 22 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100