Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-11-09   #11 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,467

Rep: 201 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 174
Folding Team Rank: 292
Trader Rating: 24
Default

thanks for the catch nathris. I must have accidentally tapped the damn trackpad and deleted that bit of code. Working on recoding the math portion.
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-11-09   #12 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,467

Rep: 201 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 174
Folding Team Rank: 292
Trader Rating: 24
Default

Here is the revised code-


Code:
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>

double getAmount(double);                           //function 1
double roundAmount(double);                        //function 2
double calcAverage_exact(double, int);           //function 3.1
double calcAverage_round(int, int);                //function 3.2
double calcStdDev_exact(double, double, int); //function 4.1
double calcStdDev_round(int, int, int);           //function 4.2
double calcDiff(double, double);                    //function 5
using namespace std;
int main()
{
    double money;
    int round_money;
    double exact_sum = 0;
    double in_sum;
    int round_sum = 0;
    double exact_squares = 0;
    int round_squares;
    int count_money = 0;
    double sumsquares_exact = 0;
    int sumsquares_round = 0; 
    
    cout<< "\nEnter an amount (0 to quit):";
    cin>> money;
while(money > 0)
{
    count_money ++;
    exact_sum += money;
    money = getAmount(money);
    round_money = (int) roundAmount(money);
    round_sum += round_money;
    exact_squares = money * money;
    sumsquares_exact += exact_squares;
    round_squares = round_money * round_money;
    sumsquares_round += round_squares;

cout<< "\nEnter an amount (0 to quit) :";
cin>> money;
}

cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);

double average_exact;
double stddev_exact;
double prct_dif;
int average_round;
int stddev_round;

average_exact = calcAverage_exact(sumsquares_exact, count_money);
average_round = (int) calcAverage_round(sumsquares_round, count_money);
stddev_exact = calcStdDev_exact(exact_sum, sumsquares_exact, count_money);
stddev_round = (int) calcStdDev_round(round_sum, sumsquares_round, count_money);
prct_dif = calcDiff(exact_sum, round_sum);

if(average_exact == -1 or average_round == -1)
cout<<"\nnot enough values to calculate the average";
if(stddev_exact == -1 || stddev_round == -1)
cout<<"\nnot enough values to calculate the standard deviation";
else

 cout<<"\nCalculation     Exact       Round";
 cout<<"\n--------------------------------------";

 cout<<"\nSum:"
               <<setw(17)
               <<exact_sum
               <<setw(12)
               <<round_sum;  
                      
cout<<"\nAverage:"
                  <<setw(13)
                  <<average_exact
                  <<setw(12)
                  <<average_round;

cout<<"\nStd Dev:"
                  <<setw(13)
                  <<stddev_exact
                  <<setw(12)
                  <<stddev_round;

if (prct_dif <= 2)
{
   cout<<"\nIts cost effective!\n";

   system ("pause");
   return 0;
}

else
    cout<<"\nIts not cost effective!\n";
    
    system ("pause");
    return 0;
}

// Function 1
double getAmount(double money)
{
if (money > 0)
{
      return money;
}     
else
if (money < 0)
{
      cout<<"\nPlease enter a valid number";
      cin>>money;
      return money;
}

else
      return 0;
}

// Function 2

double roundAmount(double money)
{ 
       double in_sum;
       int round_money;
       in_sum = (money + 5) / 10;
       round_money = (int) in_sum * 10;
       return round_money;
}
       
// Function 3.1

double calcAverage_exact(double exact_sum, int count_money)
{
       double average_exact;
       if (count_money > 1)       
       {
       average_exact = exact_sum / count_money ;
       return average_exact;;
       }
       else
       return -1;
}

// Function 3.2

double calcAverage_round(int round_sum, int count_money)
{
       double average_round;
       if (count_money > 1)       
       {
       average_round = round_sum / count_money;
       return average_round;
       }
       else
       return -1;
}

// Function 4.1

double calcStdDev_exact(double exact_sum, double sumsquares_exact, int count_money)
{
       double stddev_exact;
       if (count_money > 1)
       {
        stddev_exact = sqrt((sumsquares_exact - (exact_sum * exact_sum / count_money))/(count_money - 1));
        return stddev_exact;
       }           
       else
       return -1;
}

//Function 4.2

double calcStdDev_round(int round_sum, int sumsquares_round, int count_money)
{
       int stddev_round;
       if (count_money > 1)
       {
        stddev_round = (int) sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
        return stddev_round;
       }           
       else
       return -1;
}

//Function 5

double calcDiff(double exact_sum, double round_sum)
{
       double prct_dif;
       prct_dif = ((fabs(exact_sum - round_sum))/exact_sum) * 100;
       return prct_dif;
}
I'm still working on the line documentation but this code should compile for you guys. For some reason my average functions don't make sense though.
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions

Last edited by tofunater : 10-11-09 at 11:12 PM
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-11-09   #13 (permalink)
Case Modder
 
Spotswood's Avatar
 
Join Date: Jul 2008
Location: New Hampshire, USA
Posts: 236

Rep: 46 Spotswood is acknowledged by some
Unique Rep: 39
Trader Rating: 0
Default

Quote:
Originally Posted by TheGrayNobleman View Post
Lastly, indenting the code so one can see the hierarchy of the if else statements would be awesome.
In Visual Studio, reformatting code is as easy as selecting the code you want to reformat (i.e. ctrl+A) and then Edit -> Advanced -> Format Selection.
__________________
Rich
Custom Wooden Case Builder
Overclock.net Mod of the Month
Spotswood is offline   Reply With Quote
Old 10-12-09   #14 (permalink)
The Dapper Swindler
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 7,126

Rep: 494 nathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven member
Unique Rep: 381
Folding Team Rank: 1016
Hardware Reviews: 1
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
Here is the revised code-


Code:
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>

double getAmount(double);                           //function 1
double roundAmount(double);                        //function 2
double calcAverage_exact(double, int);           //function 3.1
double calcAverage_round(int, int);                //function 3.2
double calcStdDev_exact(double, double, int); //function 4.1
double calcStdDev_round(int, int, int);           //function 4.2
double calcDiff(double, double);                    //function 5
using namespace std;
int main()
{
    double money;
    int round_money;
    double exact_sum = 0;
    double in_sum;
    int round_sum = 0;
    double exact_squares = 0;
    int round_squares;
    int count_money = 0;
    double sumsquares_exact = 0;
    int sumsquares_round = 0; 
    
    cout<< "\nEnter an amount (0 to quit):";
    cin>> money;
while(money > 0)
{
    count_money ++;
    exact_sum += money;
    money = getAmount(money);
    round_money = (int) roundAmount(money);
    round_sum += round_money;
    exact_squares = money * money;
    sumsquares_exact += exact_squares;
    round_squares = round_money * round_money;
    sumsquares_round += round_squares;

cout<< "\nEnter an amount (0 to quit) :";
cin>> money;
}

cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);

double average_exact;
double stddev_exact;
double prct_dif;
int average_round;
int stddev_round;

average_exact = calcAverage_exact(sumsquares_exact, count_money);
average_round = (int) calcAverage_round(sumsquares_round, count_money);
stddev_exact = calcStdDev_exact(exact_sum, sumsquares_exact, count_money);
stddev_round = (int) calcStdDev_round(round_sum, sumsquares_round, count_money);
prct_dif = calcDiff(exact_sum, round_sum);

if(average_exact == -1 or average_round == -1)
cout<<"\nnot enough values to calculate the average";
if(stddev_exact == -1 || stddev_round == -1)
cout<<"\nnot enough values to calculate the standard deviation";
else

 cout<<"\nCalculation     Exact       Round";
 cout<<"\n--------------------------------------";

 cout<<"\nSum:"
               <<setw(17)
               <<exact_sum
               <<setw(12)
               <<round_sum;  
                      
cout<<"\nAverage:"
                  <<setw(13)
                  <<average_exact
                  <<setw(12)
                  <<average_round;

cout<<"\nStd Dev:"
                  <<setw(13)
                  <<stddev_exact
                  <<setw(12)
                  <<stddev_round;

if (prct_dif <= 2)
{
   cout<<"\nIts cost effective!\n";

   system ("pause");
   return 0;
}

else
    cout<<"\nIts not cost effective!\n";
    
    system ("pause");
    return 0;
}

// Function 1
double getAmount(double money)
{
if (money > 0)
{
      return money;
}     
else
if (money < 0)
{
      cout<<"\nPlease enter a valid number";
      cin>>money;
      return money;
}

else
      return 0;
}

// Function 2

double roundAmount(double money)
{ 
       double in_sum;
       int round_money;
       in_sum = (money + 5) / 10;
       round_money = (int) in_sum * 10;
       return round_money;
}
       
// Function 3.1

double calcAverage_exact(double exact_sum, int count_money)
{
       double average_exact;
       if (count_money > 1)       
       {
       average_exact = exact_sum / count_money ;
       return average_exact;;
       }
       else
       return -1;
}

// Function 3.2

double calcAverage_round(int round_sum, int count_money)
{
       double average_round;
       if (count_money > 1)       
       {
       average_round = round_sum / count_money;
       return average_round;
       }
       else
       return -1;
}

// Function 4.1

double calcStdDev_exact(double exact_sum, double sumsquares_exact, int count_money)
{
       double stddev_exact;
       if (count_money > 1)
       {
        stddev_exact = sqrt((sumsquares_exact - (exact_sum * exact_sum / count_money))/(count_money - 1));
        return stddev_exact;
       }           
       else
       return -1;
}

//Function 4.2

double calcStdDev_round(int round_sum, int sumsquares_round, int count_money)
{
       int stddev_round;
       if (count_money > 1)
       {
        stddev_round = (int) sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
        return stddev_round;
       }           
       else
       return -1;
}

//Function 5

double calcDiff(double exact_sum, double round_sum)
{
       double prct_dif;
       prct_dif = ((fabs(exact_sum - round_sum))/exact_sum) * 100;
       return prct_dif;
}
I'm still working on the line documentation but this code should compile for you guys. For some reason my average functions don't make sense though.

You can't divide a double by an integer. Well, actually you can but depending on the compiler you're going to get precision errors.

Code:
double calcAverage_exact(double exact_sum, int count_money)
{
       double average_exact;
       if (count_money > 1)       
       {
       average_exact = exact_sum / (double)count_money ;
       return average_exact;;
       }
       else
       return -1;
}
And actually what I would probably write is

Code:
double calcAverage_exact(double exact_sum, int count_money)
{
if (count_money) return (exact_sum / (double)count_money); else return -1;
}

System: The Possum
CPU
e8400 @ 4GHz (500x8)
Motherboard
P5Q Deluxe
Memory
4GB G.SKILL DDR2-1000
Graphics Card
XFX Radeon HD 4870 XXX (840/1078)
Hard Drive
WD6401AALS
Sound Card
X-Fi Platinum Fatal1ty Championship Gamer Edition
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Xigmatek HDT-S1283 w/XLF-F1253
GPU cooling
Accelero Twin Turbo
OS
Windows 7 Professional
Monitor
Samsung 2443BW 24"
nathris is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Old 10-12-09   #15 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

Join Date: Sep 2006
Location: Dekalb, IL
Posts: 2,467

Rep: 201 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 174
Folding Team Rank: 292
Trader Rating: 24
Default

I just did as you suggested Nathris, but I'm still getting an incorrect value for the average. Its still showing me that the average of 100 + 100 + 100 / 3 = 10000
__________________

Quote:
Originally Posted by iandh View Post
People like this know deep down inside that they are absolutely worthless, so they must constantly come up with new ways to give themselves worth, otherwise they may be tempted to end it all one day by OD'ing on Care-Bears marathons.

System: Hedonism, Stanford Style
CPU
i7 920 D0
Motherboard
Asus P6T6 WS revolution
Memory
6 gigs G-skill
Graphics Card
Tri-sli 260's
Hard Drive
620aaks
Sound Card
on board
Power Supply
Zalman 850
Case
hardwood techstation(soon)
CPU cooling
GTZ/bix 360/355 (soon)
GPU cooling
water (soon)
OS
Vista 64
Monitor
22" Samsung 225BW
Overclock.net - 2009 Chimp Challenge Champions
tofunater is online now I fold for Overclock.net   Reply With Quote
Old 10-12-09   #16 (permalink)
The Dapper Swindler
 
nathris's Avatar
 
intel ati

Join Date: Sep 2007
Location: Canada
Posts: 7,126

Rep: 494 nathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven membernathris is a proven member
Unique Rep: 381
Folding Team Rank: 1016
Hardware Reviews: 1
Trader Rating: 0
Default

Quote:
Originally Posted by tofunater View Post
I just did as you suggested Nathris, but I'm still getting an incorrect value for the average. Its still showing me that the average of 100 + 100 + 100 / 3 = 10000

Try putting some debug statements in there, like actually output the expression before you calculate it, so you can make sure that your actual values are correct. (For example, you might be dividing by 0.03, or instead of 100.00 you're calculating 10000. Both of them would give you that answer)

System: The Possum
CPU
e8400 @ 4GHz (500x8)
Motherboard
P5Q Deluxe
Memory
4GB G.SKILL DDR2-1000
Graphics Card
XFX Radeon HD 4870 XXX (840/1078)
Hard Drive
WD6401AALS
Sound Card
X-Fi Platinum Fatal1ty Championship Gamer Edition
Power Supply
Corsair HX750W
Case
CM690
CPU cooling
Xigmatek HDT-S1283 w/XLF-F1253
GPU cooling
Accelero Twin Turbo
OS
Windows 7 Professional
Monitor
Samsung 2443BW 24"
nathris is offline I fold for Overclock.net Overclocked Account   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:02 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.14080 seconds with 8 queries