Forum: C++ Jan 15th, 2007 |
| Replies: 3 Views: 1,312 Re: Setprecision help please Good for your compiler! The stored value of a floating point number has a limited precision, probably 50 or 60 bits. This is equivalent to a certain number of decimal digits, say about 15. If the... |
Forum: C++ Jan 7th, 2007 |
| Replies: 17 Views: 1,631 Re: It's cinfull! So what's a poor programmer to do? Since it's apparently not possinble to know when this troubelsome newline char will appear would you recommend that cin.ignore() be used before any call to cin >>?... |
Forum: C++ Jan 6th, 2007 |
| Replies: 17 Views: 1,631 Re: It's cinfull! Thanks for the explanation. I still have a question. Now I can't see why the
little program below works.
#include <iostream>
using namespace std;
main()
{ int x,y;
cout << "Enter x: ";
... |
Forum: C++ Jan 1st, 2007 |
| Replies: 17 Views: 1,631 It's cinfull! In using "cin" for getting input I have about a 99% success rate. In the remaining
1% of cases the program does not pause for input. What causes this and how does one fix it?
In ancient times when... |
Forum: C++ Feb 10th, 2006 |
| Replies: 2 Views: 1,112 Forbidden function names in Dev_C++? Calling all Dev_C++ users,
Here's a mystery! The following little program, which determines whether one integer is a divisor of another or not, compiles and runs fine using Borland's... |
Forum: C++ Sep 20th, 2005 |
| Replies: 10 Views: 1,781 |
Forum: C++ Jul 28th, 2005 |
| Replies: 1 Views: 3,226 external variables in a multifile program I have a question on external variables in a multifile program.
Quoting from K&R (first addition, page 72)
"By default, external variables are also "global", so that all references to such a... |
Forum: C++ Jul 6th, 2005 |
| Replies: 2 Views: 5,429 Re: need a little help with standard deviation You seem to have computed the average correctly. The most efficient way to compute the standard deviation is to use the formula
st. dev. = sqrt( (sum of squares -ct*square of av)/(ct - 1) )
so... |
Forum: C++ Jul 2nd, 2005 |
| Replies: 10 Views: 8,613 Re: help with Greatest common divisor I think I've already answered this but I'll do it in more detail.
x is divisible by i if the remainder when x is divided by i is 0, that is, x is divisible by i if and only if x%i == 0. Likewise, y... |
Forum: C++ Jul 1st, 2005 |
| Replies: 10 Views: 8,613 Re: help with Greatest common divisor The original posting (minah1984) seems to be using the definition of gcd to find the gcd. That's not a bad idea. The one thing missing is that he/she doesn't know how to tell whether i is a common... |
Forum: C++ Jul 1st, 2005 |
| Replies: 20 Views: 12,783 Re: Program that determines if a number is prime Your program doesn't make use of the efficiencies I mentioned. For one thing, you test possible factors up to valuex/2 but you only have to go up to sqrt(valuex), which is much smaller. (For example,... |
Forum: C++ Jun 30th, 2005 |
| Replies: 20 Views: 12,783 Re: Program that determines if a number is prime Someone commented that to see if n is a prime you only have to check possible divisors < sqrt(n). In addition, you can decrease the computing time a lot by testing the divisor 2 , then 3, 5, 7...,... |
Forum: C++ Jun 30th, 2005 |
| Replies: 3 Views: 2,441 Re: Pointer to function as an argument Thanks a lot! Your program works fine and it tells me just what I need to know. I thought that I'd have to say in the declaration of F that *f is a function of two variables and I didn't know how to... |
Forum: C++ Jun 29th, 2005 |
| Replies: 3 Views: 2,441 Pointer to function as an argument Attached is a tiny program in which the function F has as an argument the function pointer double (*f) (double). F returns the sum f(1)+f(2)+f(3)+f(4).
(Naturally, I have a much more interesting... |
Forum: C++ May 30th, 2005 |
| Replies: 2 Views: 1,423 Re: help me in primmitive root There are a number of problems with your program. The main one is that, while it prints out a lot of stuff that you don't need to see, it never performs the tests it's supposed to. Where do you test... |
Forum: Computer Science and Software Design Apr 27th, 2005 |
| Replies: 2 Views: 3,686 Re: PseudoCode Help For Newbie I think that your "pseudocode" suffers from imprecision. If you tried to turn it into code in some language that you know (C, Pascal, Basic, or whatever) you'd see the problem. You could also check... |
Forum: C++ Apr 20th, 2005 |
| Replies: 2 Views: 1,912 Re: reading records from a file Might it be that "employees" is ambiguous? It's both the name of the an array of integers and it's also a type that you've defined. (struct employees). |
Forum: C Apr 4th, 2005 |
| Replies: 3 Views: 4,583 Re: Combinations(N choose R) ? One problem is that you'r not correctly initializing the variables in calcCNR. The last variable is where the result appears. When you call the function this variable has no significant value. I'm... |
Forum: C Mar 23rd, 2005 |
| Replies: 1 Views: 1,731 Re: Input for a solution to matrix problem Here's an idea for how to partially solve the problem. I'm assuming that this is not for a first course in programming or CS. Specifically, I'm assuming you've studied trees (not just binary trees).... |
Forum: C++ Mar 20th, 2005 |
| Replies: 11 Views: 11,351 |
Forum: Computer Science and Software Design Mar 2nd, 2005 |
| Replies: 1 Views: 3,175 Re: Floating Point Representation I don't know what "unnormalized" means, but here's how to write it as a normalized floating pt. number: Since the smallest pwer of 2 bigger than the given number is 32, write it as
21.426304 =... |
Forum: Computer Science and Software Design Mar 1st, 2005 |
| Replies: 2 Views: 2,858 Re: I hit a brick wall-- time complexity problem This looks like a variation on binary search. It divides the range a1..an into three equal pieces (roughly) and uses two comparisons to determine in which third x lies. The worst case occurs (I... |
Forum: C++ Feb 23rd, 2005 |
| Replies: 3 Views: 1,671 Re: Developing A Class First, a tangential comment. Your function "addem" has a problem. You want the answers to appear in the variables na and da, so you'r asking the function to change the value of variables on the... |
Forum: C++ Feb 22nd, 2005 |
| Replies: 1 Views: 1,526 Re: Need help with a program that calc Tax Here are a few observations.
1: Your class has only public members. You're probably supposed to make the variable members private. (This isn't required by C++, but what's the point of classes if you... |
Forum: C++ Feb 17th, 2005 |
| Replies: 11 Views: 2,327 Re: need help w/ typedef I have 2 questios.
1: what do the error messages say?
2: It looks to me like the whole program is turned into a comment! If not, whats the /* doing? |
Forum: C++ Feb 17th, 2005 |
| Replies: 10 Views: 4,559 |
Forum: C++ Feb 16th, 2005 |
| Replies: 10 Views: 4,559 |
Forum: C++ Feb 16th, 2005 |
| Replies: 10 Views: 4,559 |
Forum: C++ Feb 16th, 2005 |
| Replies: 10 Views: 4,559 |
Forum: C++ Feb 15th, 2005 |
| Replies: 5 Views: 2,639 Re: hop over decimal and straight to business Your example of 6Z's in base 36 ought to work if you interpret it as an unsigned long integer. The value of this number is 36^6 -1, which is about 2 billion 176 million. which is well within the... |
Forum: C Feb 14th, 2005 |
| Replies: 6 Views: 10,848 |
Forum: C Feb 14th, 2005 |
| Replies: 6 Views: 10,848 Re: Transpose a matrix Your program won't work. The reason is that when you write matrix[i][j] = matrix[j][i] you've lost the contents of matrix[i][j] forever and you can't get it back to put in position [[j][i]. This will... |
Forum: C++ Feb 14th, 2005 |
| Replies: 5 Views: 2,639 Re: hop over decimal and straight to business In order to change the basis you have to do arithmetic. For instance, if you're talking about integers, then the rightmost digit to base N is gotten by dividing the number by N and taking the... |
Forum: C++ Feb 8th, 2005 |
| Replies: 2 Views: 2,022 |
Forum: C++ Feb 8th, 2005 |
| Replies: 2 Views: 2,022 Friend classes? A rather old C++ book I have says that one class may be declared a friend class of a second, and then the first class can access the private data of the second. I tried this example
[code]
#include... |
Forum: C Feb 8th, 2005 |
| Replies: 5 Views: 2,317 Re: needed recursion help I'm not sure I know what you mean by having it "all the way to prime number checking". I'll guess that you mean that you know how to check whether the given number is a prime or not. If you find that... |
Forum: C++ Feb 7th, 2005 |
| Replies: 2 Views: 2,488 Re: c++ classes For starters, you'll need 2 constructors. One will be something like
rational(int m, int n)
{ num = m;
den = n; //You really should check for n == 0
}
[\code]
and the other (the default) would... |
Forum: C++ Feb 6th, 2005 |
| Replies: 2 Views: 3,532 Re: calling a decimal function You don't need a private function.. Here's a simple fraction class. I hope this works. The last time I tried attaching a file I didn't succeed.) |
Forum: C++ Feb 6th, 2005 |
| Replies: 2 Views: 3,532 Re: calling a decimal function You don't need a private function here. Also I don't think it's a good idea to make the numerator and denominator doubles. For one thing, they may not print out properly, i.e., you may have a... |
Forum: C++ Jan 31st, 2005 |
| Replies: 2 Views: 6,607 |