Help with Code (function)

This is a discussion on Help with Code (function) within the C++ Programming forums, part of the General Programming Boards category; Can some1 help tell me y my function keeps having errors? I want the user to enter 4 price s, ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    12

    Help with Code (function)

    Can some1 help tell me y my function keeps having errors? I want the user to enter 4 price s, total sales each products sale is worth 25% of the sale. I wanna take these 4 products and calculate an average and return the value to the variable slsAvg. Is my function prototype, call, and function that much off?

    Code:
    double calcAveragefunc(double towers, double monitors, double printers, double desks, double slsAvg)
    {
          return slsAvg;
          }
                           
    using namespace std;
    
    int main(){
        
        double towers;
        double monitors;
        double printers;
        double desks;
        double totalProductSales;
        double slsAvg;
        
        cout << "Enter towers price: "; 
        cin >> towers;
        cout << "Enter monitors price: ";
        cin>> monitors;
        cout << "Enter printers price: ";
        cin >> printers;
        cout << "Enter desks price: ";
        cin >> desks;
        
        totalProductSales = towers + monitors + printers + desks * 25;
        
        slsAvg = totalProductSales / 4;
        
        return 0;
    }
    double calcAveragefunc(double towers, double monitors, double printers, double desks, double slsAvg)
    {
         return slsAvg;
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    It's late, but what exactly is that *25 for?

    a+b+c+d/4 is your average. Or perhaps within your question there's something that I'm missing.

    Code:
        void calculate(double a, double b, double c, double d)
         {
         double e=a+b+c+d;
         double pcent=e/4;
         cout<<pcent;
         }
    
    int main()
    {
    double aa, bb, cc, dd;
        cout<<"enter aa";
        cin>>aa;
        cout<<"enter bb";
        cin>>bb;
        cout<<"enter cc";
        cin>>cc;
        cout<<"enter dd";
        cin>>dd;
    calculate(aa,bb,cc,dd);
    cin.get();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  4. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

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