Thread: How do I get Rid of Warning messages after I compile??

  1. #1
    BBain80
    Guest

    How do I get Rid of Warning messages after I compile??

    I just finished my Program #3 for my first C++ class and I have a couple of qeustions about it. Our teacher gave us the main coding to this, all we had to do was define the functions of the program to make it run properly. Well, after I have defined the functions and compile and link it, it gives me "warning messages" about changing assignment "int" to "double". Could someone look over my program and please explain to me how to fix this? Also, does anyone have any suggestions on changing anything about this program? The program does what it is suppost to do, but is there anything that should be "fine-tuned". Your help is much appreciated!!!! Thanks, Brent


    //This program will takes the input of purchases and returns the total charge with taxes and computes the change.

    #include <iostream>
    #include <cmath>
    using namespace std;

    double SumPurchases (void);
    // Computes the total purchase price

    double ComputeDiscount (double);
    // Computes the customer's discount based on their total purchase price

    double ComputeTax (double);
    // Computes the amount of sales tax on the total after discount

    void PrintChange (double, double);
    // Displays the change in bills and coins that the cashier should give
    // the customer

    int main ( )
    {
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision (2);

    double total, discount, tax, grandTotal, payment;

    total = SumPurchases ( );
    cout << endl << endl << endl;
    cout << "The total purchase price is $ " << total << endl;

    discount = ComputeDiscount (total);
    cout << "Your discount is $ " << discount << endl;
    total = total - discount;
    cout << "The total less discount is $ " << total << endl;

    tax = ComputeTax (total);
    cout << "Your tax (at 9%) is " << tax << endl;
    grandTotal = total + tax;
    cout << "Your total including tax is $ " << grandTotal << endl;

    cout << "Amount accepted from customer is : $ ";
    cin >> payment;

    cout << endl << endl;
    PrintChange (grandTotal, payment);
    return 0;
    }

    double SumPurchases (void)// This function recieves the price and the quantity of the items purchased.
    { // and returns the total amount of purchases.
    int quantity;
    double price, TotalPurchase=0;
    while (price > 0 && quantity > 0)
    {
    cout <<"Enter price of the item and the quantity purchased (0 0 to exit):";
    cin >> price >> quantity;
    TotalPurchase = TotalPurchase + (price * quantity);
    }
    return TotalPurchase;
    }

    double ComputeDiscount(double TotalPurchase)// Function computes the discount rate of the purchase.
    {
    double discount, RoundedDiscount;
    if(TotalPurchase > 500)
    discount = TotalPurchase * .10;
    else if(TotalPurchase > 250 && TotalPurchase <=500)
    discount = TotalPurchase * .05;
    else if(TotalPurchase<= 250)
    discount = 0;
    RoundedDiscount= floor((discount*100)+0.50)/ 100;
    return RoundedDiscount;
    }

    double ComputeTax(double total_amount)// Function returns the amount of the tax to be charged to the customer.
    {
    double tax, rounded_tax;
    tax = total_amount * 0.09;
    rounded_tax = floor((tax * 100) + 0.5)/ 100;
    return rounded_tax;
    }

    void PrintChange (double bill, double payment)// This function determines the amount of change, then gives the number
    { // of bills and coins to be give the customer.
    double change;
    int twenties, tens, fives, ones, quarters, dimes, nickels, pennies;
    cout << "Your bill is:$" << bill << endl;
    cout << "You paid:$" << payment << endl;
    change = payment - bill;
    cout << "Your change is:$" << change << endl;
    if (change >= 20)
    {
    twenties = change/20;
    change=change-(twenties*20.0);
    cout <<"\t"<<twenties <<"\t"<<"20-dollar bills" <<endl;}
    else
    cout <<"\t"<<"0"<<"\t"<<"20-dollar bills" <<endl;
    if (change >= 10 && change < 20)
    {
    tens= change/10;
    change= change-(tens*10.0);
    cout <<"\t"<< tens <<"\t"<<"10-dollar bills" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"10-dollar bills" <<endl;

    if (change >= 5 && change< 10)
    {
    fives=change/5;
    change=change-(fives*5.0);
    cout <<"\t"<< fives <<"\t"<<"5-dollar bills" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"5-dollar bills" <<endl;
    if (change>=1 && change < 5)
    {
    ones=change/1;
    change=change-(ones*1.0);
    cout <<"\t"<< ones <<"\t"<<"1-dollar bills" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"1-dollar bills" <<endl;
    if (change >= .25 && change < 1)
    {
    quarters=change/0.25;
    change=change-(quarters* 0.25);
    cout <<"\t"<< quarters <<"\t"<<"quarters" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"quarters" <<endl;
    if (change >= .10 && change < .25)
    {
    dimes=change/.10;
    change=change-(dimes*.10);
    cout <<"\t"<< dimes <<"\t"<<"dimes" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"dimes" <<endl;
    if (change >= .05 && change<.10)
    {
    nickels=change/.05;
    change=change-(nickels*.05);
    cout <<"\t"<< nickels<<"\t"<<"nickels" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"nickels" <<endl;
    if (change>= .00 && change <.05)
    {
    pennies=change/.01;
    change=change-(pennies*.01);
    cout <<"\t"<< pennies <<"\t"<<"pennies" <<endl;
    }
    else
    cout <<"\t"<<"0"<<"\t"<<"pennies" <<endl;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >it gives me "warning messages" about changing assignment "int" to "double".
    What compiler do you use? That shouldn't be a warning because there's no potential loss of data. It compiles without error or warning on MSVC++.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    If you just want to not see those warning messages, then you can either do an explicit type cast for all those "int" to "double" assignments, or you can put a "#pragma warning(dissable:????)" command towards the top of your code where ???? is the number of the compiler warning that gets spit out.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    BBain80
    Guest

    compiler Info

    I use PcGrasp, with a Cygnus Beta 20 Compiler, Is there anyway to change, in the program, an assigned value from Int to Double, or Visa versa??

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > Is there anyway to change, in the program, an assigned value from Int to Double, or Visa versa??

    Yes - it's called casting.

    double i = 4.0534;
    int j;
    j = (int) i;

    In the example above, i is represented as an integer, for that line only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The biggest project I've worked on: ASCIIpOrtal
    By guesst in forum Projects and Job Recruitment
    Replies: 19
    Last Post: 07-21-2009, 04:42 AM
  2. File Server Help
    By lautarox in forum C Programming
    Replies: 146
    Last Post: 09-24-2008, 06:32 PM
  3. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM