|
|
|
#1 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
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;
}
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
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:
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:
The standard deviation is calculated by implementing the following formula: [IMG]file:///C:/Documents%20and%20Settings/tofunater/Desktop/240pgm4_files/240sd.gif[/IMG] where
7.5 3.6 4.8 5.0then
[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.
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | ||||||||||||||
|
4.0ghz
![]() |
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:
|
||||||||||||||
|
|
|
|
#4 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
Thanks gooda, I apoligize for the appearance, but it deleted all my formatting when I copy and pasted it.
|
|||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||
|
PC Gamer
![]() |
Working on cleaning it up now. I will post what I can find in say 30 mins or so.
__________________
|
||||||||||
|
|
|
|
|
#6 (permalink) | ||||||||||||||||
|
4.0ghz
![]() |
Quote:
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;
}
Quote:
~Gooda~
__________________
Start folding HERE! Quote:
|
||||||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
Thank you
|
|||||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||
|
PC Gamer
![]() |
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;
}
__________________
Last edited by TheGrayNobleman : 09-24-09 at 05:25 PM |
||||||||||
|
|
|
|
|
#9 (permalink) | ||||||||||||
|
Programmer
![]() |
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)); Code:
double sqrt ( double x );
float sqrt ( float x );
long double sqrt ( long double x );
Try if this version works: Code:
stddev_round = sqrt((double)(sumsquares_round - (round_sum * round_sum / count_money))/(count_money - 1));
|
||||||||||||
|
|
|
|
|
#10 (permalink) | |||||||||||||
|
Folding Fanatic
![]() |
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 '&&'.
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|