Thread: math with decimals

  1. #1
    Registered User wayko's Avatar
    Join Date
    Sep 2001
    Posts
    28

    Talking math with decimals

    why doen't my program multiple the decimal numbers

    #include <iostream.h>
    #include <string.h>
    #include <math.h>
    int main ()
    {
    int amount;
    int price;
    int total;
    cout << "Enter the current amount:";
    cin >> amount;
    cout << "Enter price : ";
    cin >> price;
    total = (amount * price);
    cout << "The total amount is : "<< total;

    return 0;
    }

    like 10 * 2.5 should = 25 but i get 20
    hello its me Wayko

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Because you have all of your variables declared as integers; declare them as doubles instead.

  3. #3
    Registered User wayko's Avatar
    Join Date
    Sep 2001
    Posts
    28
    thanx it works
    is there a way to send the results to a txt file or database file?
    hello its me Wayko

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    79
    #include <fstream>
    //other include files
    //
    //


    using namespace std;

    int main()
    {
    //your own stuff
    //
    //
    ofstream fout;
    fout.open("testfile.txt");
    fout << myvar1 << myvar2; //etc..
    fout.close();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 05:36 PM
  2. Help with C++ Math
    By aonic in forum C++ Programming
    Replies: 4
    Last Post: 01-29-2005, 04:40 AM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 06:39 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM