Thread: Can't fix warning- some input...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    39

    Can't fix warning- some input...

    Got a warning...like to fix...(I know warning are generally fine...but want to fix)- In bold

    20 C:\Documents and Settings\HP_Owner\Desktop\PA2C.cpp [Warning] passing `double' for converting 3 of `double futureInvestmentValue(double, double, int)'


    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    
    double futureInvestmentValue(double IA, double MIR, int NOY);
    
    int main()
    {
      double investmentAmount, annualInterestRate, numOfYears,  monthlyInterestRate, futureValue;
      
      cout << "Enter investment amount: ";
      cin >> investmentAmount;
      cout << "Enter monthly interest rate: ";
      cin >> annualInterestRate;
      cout << "Enter number of years: ";
      cin >> numOfYears;
    
      monthlyInterestRate = annualInterestRate / 1200;
      
      futureValue = futureInvestmentValue(investmentAmount,monthlyInterestRate,numOfYears); 
    
      cout << "Future value is " << futureValue << endl;
      
      return 0;
    }
    double futureInvestmentValue(double investmentAmount, double monthlyInterestRate, int numOfYears)
    {
         double accumulatedValue;  
         
         accumulatedValue = investmentAmount * pow(1 + monthlyInterestRate, numOfYears * 12);
         
         return accumulatedValue;
    }

  2. #2
    Registered User
    Join Date
    Jan 2007
    Posts
    35
    we enginners bother only about errors not WARNINGS !!!!!!!!!!!!!!!!!!!



    so ignore it

    ...
    sorry i didnt read your post

  3. #3
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    It is a warning, so you can ignore it. But the problem is that you have said that numOfYears is a double, when the futurInvestmentValue function is asking for an int.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Your third parameter 'numOfYears' to the function is supposed to be an int, but you pass it a double

    Code:
    double investmentAmount, annualInterestRate, numOfYears,  monthlyInterestRate, futureValue;
    So you get an implicit type conversion

    Floating to Integral (C++)
    Standard Conversions (C++)

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > we enginners bother only about errors not WARNINGS !!!!!!!!!!!!!!!!!!!
    > so ignore it
    You're not an engineer then.

    All warnings are errors.

    If you have warnings, you're on the slippery slope of seeing "how much can I get away with before it breaks".
    One or two is OK (usually), but by the time you're up into the 1000's, you've got a big-assed problem on your hands.

    What's worse, with 1000's of warnings, you just don't see 1001 appear as one you REALLY should be paying attention to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    39
    Thanks got the warning fixed...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Using malloc
    By ulillillia in forum C Programming
    Replies: 34
    Last Post: 02-20-2008, 06:41 PM
  3. Need some help with C program writing
    By The_PC_Gamer in forum C Programming
    Replies: 9
    Last Post: 02-12-2008, 09:12 PM
  4. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM