Forum: C++ Dec 28th, 2008 |
| Replies: 13 Views: 1,159 @VernonDozier: Yes, you're obviously right, I just wanted to make it as plain as possible for the OP :) |
Forum: C++ Dec 28th, 2008 |
| Replies: 13 Views: 1,159 I hope this is not homework, so I'll show you a little more (it's simpler than it seems!) #include <iostream>
#include <string>
using namespace std;
int char2int(char c) {
switch(c) {
... |
Forum: C++ Dec 28th, 2008 |
| Replies: 13 Views: 1,159 You could use atoi (http://www.cplusplus.com/reference/clibrary/cstdlib/atoi.html) or write your own char-to-digit converter, like this: int char2int(char c) {
switch(c) {
case '0':... |
Forum: C++ Dec 23rd, 2008 |
| Replies: 9 Views: 808 If a function returns, say, an int, you can use a call to that function in every place you could have used an int.
Examples:
#include <iostream>
int sumFunction(int a, int b) {
return a +... |
Forum: C++ Dec 14th, 2008 |
| Replies: 7 Views: 806 What prevents your program from compiling is the following:
1) close doesn't need arguments - change both a.close("phonedir"); with a.close();.
2) else "" ; doesn't make sense. Maybe you wanted... |
Forum: C++ Dec 14th, 2008 |
| Replies: 2 Views: 320 Change a[i]= tmp; with a += tmp;. |
Forum: C++ Dec 14th, 2008 |
| Replies: 7 Views: 806 getline(cin, line);
Shouldn't you take your line from the ifstream?
What daviddoria meant with the add function is that you are every time rewriting the file instead of just adding lines.
... |
Forum: C++ Dec 12th, 2008 |
| Replies: 11 Views: 943 string myFile("rawDictionary2");
int totalWords= wordCount(myFile);
you are sending in a string, why do you want it to accept an ifstream? |
Forum: C++ Dec 4th, 2008 |
| Replies: 9 Views: 452 Well if it's multiplication it's trivial... but I don't see any purpose in mentioning logarithms. Waiting for others to express their opinion on the matter.
Only thing I'd like to add is: avoid... |
Forum: C++ Dec 4th, 2008 |
| Replies: 9 Views: 452 First general advice: use code tags (here (http://www.daniweb.com/forums/misc-explaincode.html) is an explanation of how) when posting code.
Second general advice: a more descriptive thread title... |
Forum: C++ Dec 4th, 2008 |
| Replies: 2 Views: 807 As long as you are decrementing y you should put y in your base cases checks, otherwise multiply(2, wathever); would result in *endless* recursion.
EDIT: Sorry, Salem beated me in speed. |
Forum: C++ Nov 30th, 2008 |
| Replies: 5 Views: 429 Seriously, how much do you think we care? Moreover, I hardly think so. I'm pretty sure that you won't hold gratitude or appreciation soon after you'll hand that assignment. Not that I'd pay a penny... |
Forum: C++ Nov 29th, 2008 |
| Replies: 3 Views: 697 You have extra parentheses: write this if(strcmp(a,b) > 0) && (strcmp(a,c) > 0)
like thisif(strcmp(a,b) > 0 && strcmp(a,c) > 0) |
Forum: C++ Nov 22nd, 2008 |
| Replies: 12 Views: 1,339 If you are making a complex class you should return a complex object, and it should not be the first operand. I mean given z and w two complex number, the instruction z + w should not modify z!... |
Forum: C++ Nov 18th, 2008 |
| Replies: 2 Views: 408 strange, #include <iostream>
using std::cout;
using std::endl;
int main(void) {
char * word = new char [20];
char temporal[ ] = "hola";
strcpy(word, temporal);
cout << word << endl; |
Forum: C++ Nov 15th, 2008 |
| Replies: 1 Views: 559 Read this (http://www.daniweb.com/forums/post9554.html). |
Forum: C++ Nov 9th, 2008 |
| Replies: 5 Views: 1,335 I'm fairly new to C++ in general and inheritance in particular so please someone correct me if I'm wrong: it seems to me like your methods definitions are conflicting with base class definitions of... |
Forum: C++ Nov 7th, 2008 |
| Replies: 4 Views: 449 return ceil(sqft/115.)*cpg; here's your total paint cost. Divide by cost per gallon and you will obtain the number of gallons used Oo (read: do not multiply for cpg).
It's the same for the number... |
Forum: C++ Nov 4th, 2008 |
| Replies: 2 Views: 1,513 val = true sets the content of val to true.
val==true checks the content of value.
They are two very different things! In your while loop and in the two if statements you need the second, so... |
Forum: C++ Nov 4th, 2008 |
| Replies: 6 Views: 3,174 I'd do it that way too, just I'd add a little if-else-abs() trick to handle n<0 (otherwise it would print -567 reversed as -7-6-5).
something like if(n<0) {
cout << "-" << abs(n%10);
... |
Forum: C++ Nov 2nd, 2008 |
| Replies: 14 Views: 857 if(Number%2==0) {
cout << Number << " is even" << endl;
}
else {
cout << Number << " is odd" << endl;
}
Number % 2 returns the rest of the division by 2 (it's called modulus). ... |