Programming Probelm - Please Help!

This is a discussion on Programming Probelm - Please Help! within the C++ Programming forums, part of the General Programming Boards category; Can someone tell me what is wrong with my program? (below) It builds without any errors, but any numbers that ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    19

    Programming Probelm - Please Help!

    Can someone tell me what is wrong with my program? (below)
    It builds without any errors, but any numbers that I input for cost and markup,
    the retail just comes out as "00411168" no matter what numbers I input.
    Help would be greatly appreciated!!!




    Code:
    #include <iostream>  
    #include <iomanip>
    using namespace std;
    
    double retail (double, double);
    
    int main()
    {
       double cost;
       double markup; 
    
       cout << "What is the item's wholesale cost? ";
       cin >> cost;
       cout << endl;
    
       cout << "What is the markup percentage? ";
       cin >> markup;
       cout << endl; 
    
       retail (cost, markup); 
    
    
       cout << "The retail price of the item is " << retail << fixed << setprecision(2) << endl;
    
    	return (0);
    
    }
    
    	double retail (double wholesaleCost, double markupPercentage)
       {
    	  
    	   return (wholesaleCost + (wholesaleCost * (markupPercentage/100)));
    
       }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    You call the retail function, yes, but you should be calling it at the place where you want to print its return value.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    19
    I should call it in the cout statement?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    Yes, instead of just using the function name like you did (which results in a function pointer, but you can ignore this for now).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    19
    so like this?

    cout << cost << markup << "The retail price of the item is " << retail << endl;

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    No, like this:
    Code:
    cout << "The retail price of the item is " << retail(cost, markup) << fixed << setprecision(2) << endl;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    19
    It worked! Thank you!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array Probelm
    By peacealida in forum C Programming
    Replies: 7
    Last Post: 04-01-2008, 07:12 AM
  2. Probelm when entering a string
    By ManiacBR in forum C++ Programming
    Replies: 4
    Last Post: 11-23-2006, 04:07 AM
  3. C and ASM probelm
    By peckitt99 in forum C Programming
    Replies: 8
    Last Post: 11-02-2006, 05:33 AM
  4. Bitmap display probelm.
    By hemanth.balaji in forum Windows Programming
    Replies: 11
    Last Post: 05-29-2005, 10:50 PM
  5. Char Variable Probelm
    By Krak in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2003, 11:34 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21