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 09-24-09   #1 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

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

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 280
Trader Rating: 24
Default C++ Compiler errors

You guys helped me so much last time, I thought I'd ask again. I've got an issue with the program below.

Code:
#include <iostream>
#include <iomanip>
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<< "n\Enter an amount (0 to quit):";
cin>> money;
while (money > 0)
{
count_money ++;
exact_sum += money;
in_sum = (money + 5) / 10; <--Line 36
round_money = in_sum * 10;
round_sum += round_money;
exact_squares = money * money;
sumsquares_exact += exact_squares;
round_squares = round_money * round_money;
sumsquares_round += round_squares;
cout<< "n\Enter an amount (0 to quit):";
cin>> money;
}
cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
double stddev_exact, stddev_round, prct_dif;
stddev_exact = sqrt((sumsquares_exact - (exact_sum * exact_sum / count_money))/(count_money - 1));
stddev_round = sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
prct_dif = ((fabs(exact_sum - round_sum))/exact_sum) * 100;
if (count_money != 1 and exact_sum != 0)
{
cout<<"n/Calculation     Exact       Round";
cout<<"n/--------------------------------------";
cout<<"n/Sum:"<<setw(10)
<<exact_sum
<<setw(6)
<<round_sum;  
                      
cout<<"n/Average:"<<setw(6)
<<prct_dif
<<setw(6)
<<prct_dif;
cout<<"n/Std Dev:"<<setw(6)
<<stddev_exact
<<setw(6)
<<stddev_round;
if (prct_dif <= 2)
{
cout<<"n/Its cost effevtive!";
system ("pause");
return 0;
}
else
cout<<"n/Its not cost effective!";
 system ("pause");
return 0;
}
else 
cout<<"n/Standard deviation or percent difference could not be calculated.";
 
system ("pause");
return 0;
}
Apparently I can not force a double variable into an int variable on line 36 and how do I get around that? Also it says I have not declared 'sqrt' and 'fabs'. Anyone know how to do that?
__________________

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 09-24-09   #2 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

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

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 280
Trader Rating: 24
Default

Here is the rubric btw. I guess I should let you know what the programs supposed to do.
---------
Overview

For this assignment, you are to write a program that will test the effect of rounding dollar amounts to the nearest $10 rather than keeping track of exact amounts. It has been determined that if the difference between the results of the two methods is less than 2%, then it would be cost effective for a company to round rather than balance to the penny.
Your program should accept dollar amounts from the user until 0 is entered. Each exact dollar amount should be rounded to the nearest $10 value. The exact and rounded amounts should then be used to keep track of:
  • the sum of the exact dollar amounts
  • the sum of the rounded dollar amounts
  • the sum of the squares of the exact dollar amounts
  • the sum of the squares of the rounded dollar amounts
  • the number of dollar amounts entered
After the user has entered an exact amount of 0, display the sum, average, and standard deviation for both the exact and rounded amounts. Calculate the percent difference between the sums of the exact and rounded amounts and make a determination as to whether or not it's cost effective to round the dollar values.
When testing your program, keep in mind that $10 is a greater percent of a small value, than of a large value. If you test with only very small numbers (like $1.35, $2.99), common sense should tell you that the results will be radically different.
Verification of exact dollar amount

The exact dollar amount should be examined to make sure that the user entered a value greater than or equal to 0. If an invalid value is entered, an error message including the invalid value should be displayed and the user should be prompted for another value. This should happen repeatedly until a valid value is entered.
Rounding

To an amount to the nearest $10 value:
  1. add 5 to the exact amount
  2. divide by 10
  3. multiply the integer result by 10.
Calculations

The standard deviation is calculated by implementing the following formula:
[IMG]file:///C:/Documents%20and%20Settings/tofunater/Desktop/240pgm4_files/240sd.gif[/IMG]
where
  • Σ( x2 ) is the sum of the squared values
  • (Σ x)2 is the square of the sum of the values
  • size is the number of values
For example, if you have the values:
7.5 3.6 4.8 5.0then
  • Σ( x2 ) is equal to(7.5 * 7.5) + (3.6 * 3.6) + (4.8 * 4.8) + (5.0 * 5.0)
  • (Σ x)2 is equal to(7.5 + 3.6 + 4.8 + 5.0) * (7.5 + 3.6 + 4.8 + 5.0)
  • size is equal to 4
The percent difference is calculated by implementing the following formula:
[IMG]file:///C:/Documents%20and%20Settings/tofunater/Desktop/240pgm4_files/240diff.jpg[/IMG]
Think about using the function fabs() to find the absolute value.
Output

The output from your program should consist of the prompts to the user to enter dollar amounts, a neatly formatted table that displays the results from the calculations, and a message indicating whether the percent difference is acceptable or unacceptable.
The basic format for the table is:
Calculation Exact Rounded------------------------------------------Sum:Average:Std Dev:If the average (and standard deviation) cannot be calculated, display a message that the average (and standard deviation) could not be calculated.
__________________

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 09-24-09   #3 (permalink)
4.0ghz
 
Havegooda's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Seaside, CA
Posts: 6,227
Blog Entries: 1

Rep: 393 Havegooda is a proven memberHavegooda is a proven memberHavegooda is a proven memberHavegooda is a proven member
Unique Rep: 279
Trader Rating: 20
Default

I'll see if I can figure something out during class. But for the love of god, formatting, learn it! Mah eyes!

~Gooda~
__________________

Start folding HERE!
Quote:
Originally Posted by alexgheseger View Post
Wow...

I never thought i'd have to say this, but any penis pictures will net you a hefty infraction mmkay?
Engineering Sample CPUs: Q6600 B0 - Xeon E3110 (E8400) E0 - E5400 (possibly) - E8400 (possibly)

System: Water Cooled Quad
CPU
E3110 Engineernig Sample
Motherboard
DFI DK X48
Memory
4x2GB G.Skill DDR2-1000
Graphics Card
9800GX2
Hard Drive
4x640GB WD AALS - RAID5
Sound Card
Onboard
Power Supply
Ultra X3 850W
Case
RocketFish (Lian-Li) by Cyberdruid
CPU cooling
D-Tek Fusion V1
GPU cooling
Full-cover waterblock.
OS
Vista Ultimate x64
Monitor
Samsung 245BW (24")
Overclock.net - 2009 Chimp Challenge Champions
Havegooda is offline Overclocked Account   Reply With Quote
Old 09-24-09   #4 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

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

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 280
Trader Rating: 24
Default

Thanks gooda, I apoligize for the appearance, but it deleted all my formatting when I copy and pasted it.
__________________

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 09-24-09   #5 (permalink)
PC Gamer
 
TheGrayNobleman's Avatar
 
intel ati

Join Date: Jun 2007
Location: Cali
Posts: 864

Rep: 70 TheGrayNobleman is acknowledged by some
Unique Rep: 65
Trader Rating: 0
Default

Working on cleaning it up now. I will post what I can find in say 30 mins or so.
__________________
(。◕‿‿◕。) (◕‿◕✿)
Basic GUIDE to keeping your computer/data protected.

System: snowRAZR
CPU
Q6600 Core 2 Quad 2.4 Ghz
Motherboard
Gigabyte EP45-UD3P
Memory
4 GB
Graphics Card
Sapphire ATI 4830
Hard Drive
320GB WD 7200 rpm
Power Supply
550W Corsair CMPSU-550VX
Case
XCLIO Windtunnel
OS
Windows 7 Professional/Windows XP 64 bit
Monitor
Samsung 19" Widescreen LCD
TheGrayNobleman is offline   Reply With Quote
Old 09-24-09   #6 (permalink)
4.0ghz
 
Havegooda's Avatar
 
intel nvidia

Join Date: Sep 2007
Location: Seaside, CA
Posts: 6,227
Blog Entries: 1

Rep: 393 Havegooda is a proven memberHavegooda is a proven memberHavegooda is a proven memberHavegooda is a proven member
Unique Rep: 279
Trader Rating: 20
Default

Quote:
Originally Posted by tofunater View Post
Thanks gooda, I apoligize for the appearance, but it deleted all my formatting when I copy and pasted it.
Should be all fixed except for one that I can't figure out. Lots of small errors like not commenting out <---Line 36, using the word and instead of &&, etc.

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

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 << "n\Enter an amount (0 to quit):";
	cin >> money;

	while (money > 0)
	{
		count_money ++;
		exact_sum += money;
		in_sum = (money + 5) / 10; //<--Line 36
		round_money = in_sum * 10;
		round_sum += round_money;
		exact_squares = money * money;
		sumsquares_exact += exact_squares;
		round_squares = round_money * round_money;
		sumsquares_round += round_squares;
		cout<< "n\Enter an amount (0 to quit):";
		cin>> money;
	}

	cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
	double stddev_exact, stddev_round, prct_dif;
	stddev_exact = sqrt((sumsquares_exact - (exact_sum * exact_sum / count_money))/(count_money - 1));
	stddev_round = sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
	prct_dif = ((fabs(exact_sum - round_sum))/exact_sum) * 100;

	if (count_money != 1 && exact_sum != 0)
	{
	cout<<"n/Calculation     Exact       Round";
	cout<<"n/--------------------------------------";
	cout<<"n/Sum:"<<setw(10)
	<<exact_sum
	<<setw(6)
	<<round_sum;  
	                      
	cout<<"n/Average:"<<setw(6)
	<<prct_dif
	<<setw(6)
	<<prct_dif;
	cout<<"n/Std Dev:"<<setw(6)
	<<stddev_exact
	<<setw(6)
	<<stddev_round;

	if (prct_dif <= 2)
	{
	cout<<"n/Its cost effevtive!";
	system ("pause");
	return 0;
	}
	if (prct_dif > 2)
	{
	cout<<"n/Its not cost effective!";
	 system ("pause");
	return 0;
	}
	else 
	cout<<"n/Standard deviation or percent difference could not be calculated.";
	 
	system ("pause");
	}
	
	return 0;
}
Only error left is...

Quote:
Error 4 error C2668: 'sqrt' : ambiguous call to overloaded function c:\documents and settings\grif9595\my documents\visual studio 2008\projects\test\test\test.cpp 42
No idea about that.

~Gooda~
__________________

Start folding HERE!
Quote:
Originally Posted by alexgheseger View Post
Wow...

I never thought i'd have to say this, but any penis pictures will net you a hefty infraction mmkay?
Engineering Sample CPUs: Q6600 B0 - Xeon E3110 (E8400) E0 - E5400 (possibly) - E8400 (possibly)

System: Water Cooled Quad
CPU
E3110 Engineernig Sample
Motherboard
DFI DK X48
Memory
4x2GB G.Skill DDR2-1000
Graphics Card
9800GX2
Hard Drive
4x640GB WD AALS - RAID5
Sound Card
Onboard
Power Supply
Ultra X3 850W
Case
RocketFish (Lian-Li) by Cyberdruid
CPU cooling
D-Tek Fusion V1
GPU cooling
Full-cover waterblock.
OS
Vista Ultimate x64
Monitor
Samsung 245BW (24")
Overclock.net - 2009 Chimp Challenge Champions
Havegooda is offline Overclocked Account   Reply With Quote
Old 09-24-09   #7 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

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

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 280
Trader Rating: 24
Default

Quote:
Originally Posted by TheGrayNobleman View Post
Working on cleaning it up now. I will post what I can find in say 30 mins or so.
Thank you
__________________

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 09-24-09   #8 (permalink)
PC Gamer
 
TheGrayNobleman's Avatar
 
intel ati

Join Date: Jun 2007
Location: Cali
Posts: 864

Rep: 70 TheGrayNobleman is acknowledged by some
Unique Rep: 65
Trader Rating: 0
Default

So I did a little research on the last error and it looks like a compiler bug with VS2008. The workaround from what I've seen so far is to manually use std::cout, std::cin, etc because the std::swap is confusing the compiler.

I know it can sometimes lose the formatting when you copy and paste so try opening the file.cpp or opening the program.cpp in notepad, then copying and pasting.

Good luck and let me know if you need any more help.

Got a lab so I'll see if I can get a working version later, as for now let me know if you can get around what I think is a bug.

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

using namespace std; //replace this with the necessary std::cout, std::cin, etc so the std::swap isn't used.

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<< "n\Enter an amount (0 to quit):";
	cin>> money;
	while (money > 0)
	{
		count_money ++;
		exact_sum += money;
		in_sum = (money + 5) / 10; //<--Line 36
		round_money = in_sum * 10;
		round_sum += round_money;
		exact_squares = money * money;
		sumsquares_exact += exact_squares;
		round_squares = round_money * round_money;
		sumsquares_round += round_squares;
		cout<< "n\Enter an amount (0 to quit):";
		cin>> money;
	}
cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
double stddev_exact, stddev_round, prct_dif;

stddev_exact = sqrt((sumsquares_exact - (exact_sum * exact_sum / count_money))/(count_money - 1));
stddev_round = sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));

prct_dif = ((fabs(exact_sum - round_sum))/exact_sum) * 100;

if (count_money != 1 && exact_sum != 0)
	{
	cout<<"n/Calculation     Exact       Round"
		<<"n/--------------------------------------"
		<<"n/Sum:"<< setw(10)
	<<exact_sum
	<<setw(6)
	<<round_sum;  
	                      
	cout<<"n/Average:"<<setw(6)
		<<prct_dif
		<<setw(6)
		<<prct_dif
		<<"n/Std Dev:"<<setw(6)
		<<stddev_exact
		<<setw(6)
		<<stddev_round;

	if (prct_dif <= 2)
		{
		cout<<"n/Its cost effevtive!";
		system ("pause");
		return 0;
		}
else
cout<<"n/Its not cost effective!";
system ("pause");
return 0;

}
else 
cout<<"n/Standard deviation or percent difference could not be calculated.";
system ("pause");
return 0;
}
__________________
(。◕‿‿◕。) (◕‿◕✿)
Basic GUIDE to keeping your computer/data protected.

System: snowRAZR
CPU
Q6600 Core 2 Quad 2.4 Ghz
Motherboard
Gigabyte EP45-UD3P
Memory
4 GB
Graphics Card
Sapphire ATI 4830
Hard Drive
320GB WD 7200 rpm
Power Supply
550W Corsair CMPSU-550VX
Case
XCLIO Windtunnel
OS
Windows 7 Professional/Windows XP 64 bit
Monitor
Samsung 19" Widescreen LCD

Last edited by TheGrayNobleman : 09-24-09 at 05:25 PM
TheGrayNobleman is offline   Reply With Quote
Old 09-24-09   #9 (permalink)
Programmer
 
intel nvidia

Join Date: Jun 2009
Location: Italy
Posts: 231

Rep: 50 pippolo is acknowledged by some
Unique Rep: 46
Trader Rating: 0
Default

Quote:
Originally Posted by Havegooda View Post
Only error left is...

....

No idea about that.
It seems that the problem is that in the row:
Code:
stddev_round = sqrt((sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
the sqrt() parameter is if type int and the available sqrt() functions are:
Code:
 double sqrt (      double x );
      float sqrt (       float x );
long double sqrt ( long double x );
When the compiler try to promote the int parameter to another type it can't decide between promote it to a float or to a double (both are valid conversions).
Try if this version works:
Code:
stddev_round = sqrt((double)(sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
otherwise the TheGrayNobleman's comment can be valid... all microsoft compilers are very buggy.
__________________
System: My System
CPU
2xQuadCore Intel Xeon E5420
Motherboard
Tyan Tempest i5400XT
Memory
16GB 8xSamsung M395T5750 FBDIMM
Graphics Card
XFX 9800GTX
Hard Drive
16 Internal, 8 external. Mainly Seagate
Sound Card
Sound Blaster X-FI Platinum Fatal1ty Champion
Power Supply
Enermax Galaxy 1000W EGA1000EWL
Case
Chieftec (modified)
CPU cooling
Cooler Master 3U-Attiva S3N-7DWHS-L5-GP
GPU cooling
Standard
OS
Vista Ultimate x64
pippolo is offline   Reply With Quote
Old 09-24-09   #10 (permalink)
Folding Fanatic
 
tofunater's Avatar
 
intel nvidia

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

Rep: 203 tofunater is acknowledged by manytofunater is acknowledged by manytofunater is acknowledged by many
Unique Rep: 176
Folding Team Rank: 280
Trader Rating: 24
Default

I did not know about the math libraries, thank you. As for the error on line 36, I did not know that I could run the program as it is just a warning.
It works now, I've just gotta clean up my width's so they lineup correctly.
What compiler are you guys utilizing? Dev C++ is what I'm using and it runs the 'and' command interchangeably with '&&'.
__________________

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
Reply


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



All times are GMT -5. The time now is 10:40 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.20326 seconds with 8 queries