Thread: Programming Probelm - Please Help!

  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
    28,413
    You call the retail function, yes, but you should be calling it at the place where you want to print its return value.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    Yes, instead of just using the function name like you did (which results in a function pointer, but you can ignore this for now).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    28,413
    No, like this:
    Code:
    cout << "The retail price of the item is " << retail(cost, markup) << fixed << setprecision(2) << endl;
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 05:07 AM
  3. C and ASM probelm
    By peckitt99 in forum C Programming
    Replies: 8
    Last Post: 11-02-2006, 06: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, 12:34 PM

Tags for this Thread