Thread: erro help newbie at C++

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    uk
    Posts
    14

    erro help newbie at C++

    Code:
    #include <iostream>
    #include <cmath>
    
    int main() {
    
    unsigned long loanAmount =
     150000;
     float annualInterestRate = 6.0;
     unsigned short loanLength = 30;
     const unsigned short
     MONTHS_IN_YEAR = 12;
     
     float monthlyInterestRate =
     annualInterestRate  / MONTHS_IN_YEAR;
      monthlyInterestRate =
       monthlyInterestRate/100;
      unsigned short numberPayments =
      loanLength * MONTHS_IN_YEAR;
     
      float monthlyPayments = 1 - pow((1 +
      monthlyInterestRate),
      numberPayments);
      
      monthlyPayment = monthlyInterestRate/
       monthlyPayment;
      monthlyPayment = loanAmount *
       monthlyPayment;  
      
      std::cout << "Assuming a loan in the 
      ammount of £" << loanAmount
      << ", at " << annualInterestRate
      << "% interest, over " << loanlength
      << " years, the monthly payment would 
      be £";
      
      std::cout.setf(std::ios_base::fixed);
      std::cout.setf(std::ios_base::
       showpoint);
      std::cout.percision(2);
      std::cout << monthlyPayment << ".\n\n";
      
      std::cout << "Press enter or return to 
      continue.\n";
      std::cin.get();
      
       return 0;
     }
    i am getting a error on this part of the code on the top line


    Code:
    monthlyPayment = monthlyInterestRate/
       monthlyPayment;
      monthlyPayment = loanAmount *
       monthlyPayment;

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    please post the error message

  3. #3
    Registered User
    Join Date
    May 2006
    Location
    uk
    Posts
    14
    sorry here it is

    24 C:\temp\Untitled1.cpp
    `monthlyPayment' undeclared (first use this function)

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    The problem is exactly what it says, you have not declared monthlyPayment. Should it be a float?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    May 2006
    Location
    uk
    Posts
    14
    this code is what im doing out of c++ book and a have write it out word for word

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    You defined monthlyPayments
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    Registered User
    Join Date
    May 2006
    Location
    uk
    Posts
    14
    thanks all got it sorted

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by raze
    this code is what im doing out of c++ book and a have write it out word for word
    most books contain errors, some are not proofread very well before publishing. You should get online with the publisher to see if they have electronic corrections you can download. Some publishers/authors also provide free electronic copies of the source code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM