CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2010
    Posts
    4

    Question First Practice Program need help...C++

    Need help with simple code for calculating interest...not compound....yet. Can not figure out what code is needed to change the -double percent- to a -decimal-.

    Giving me the error:

    ------ Build started: Project: Practice_Work, Configuration: Debug Win32 ------
    Practice_Work.cpp
    Practice_Work.cpp(24): error C2440: '=' : cannot convert from 'Systemecimal' to 'double'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Here is the Code i have written so far:

    Code:
    // Practice_Work.cpp : main project file.
    // calculating intrest over one fixed period
    
    #using <mscorlib.dll>
    #include <iostream>
    using namespace System;
    using namespace std;
    
    
    int main()
    {
    
    //declaring variables
    
    double number= 0.0;
    double percent= 0.0;
    double difference= 0.0;
    double sum= 0.0;
    
    //Algorithms: assigning integers to variables
    
    Console::WriteLine("Enter Amount: ");
    number= Convert::ToDouble(Console::ReadLine());
    Console::WriteLine("Enter Intrest Rate: ");
    percent= Convert::ToDouble(Console::ReadLine());
    percent= Convert::ToDecimal(percent);
    
    
    //Calculations for solving the algorithm
    
    difference= number*percent;
    sum= number + difference;
    
    //Printing out the results
    
    Console::WriteLine("Total amount after interest equals: ",Convert::ToString(sum));
    
    
    cin.get();
    
    return  0;
    
    }
    Last edited by Jeff.Brown; October 18th, 2010 at 09:09 AM.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: First Practice Program need help...C++

    Code:
    percent= Convert::ToDouble(Console::ReadLine());
    percent= Convert::ToDecimal(percent);
    Why do you need both lines? Use only one of them:
    Code:
    double percent= 0.0;
    percent= Convert::ToDouble(Console::ReadLine());
    If you want to use ToDecimal, declare percent as decimal.

  3. #3
    Join Date
    Oct 2010
    Posts
    4

    Re: First Practice Program need help...C++

    Actually i figured it out, it was a simple issue with the math. Thank you for your help though, i ended up looking into that. funny how a break from constantly staring at code can produce simple answers lol

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: First Practice Program need help...C++

    If you are compiling in the IDE, if you double click on the error in the errors window, it will take you right to the offending line of code.

    After a short time, you'll pretty much know what the errors mean and how to fix them. Before then, just copy the error text into a bing or google search for additional hints on how to solve them.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured