Forum: C++ Apr 23rd, 2008 |
| Replies: 3 Views: 2,919 Thanks AD. I'm in the process of coming to grips with all or most of the basic cin uses and I was more concerned with why an error state is recorded when there is a newline left in the input buffer... |
Forum: C++ Apr 22nd, 2008 |
| Replies: 3 Views: 2,919 I'm self studying C++ and I'm actually back-tracking a bit in order to clarify things. My question revolves around why in the following code is the cin.fail() == true.
#include <iostream>... |
Forum: C++ Apr 15th, 2008 |
| Replies: 11 Views: 3,193 Good pick up. It appears that the variable ch needs to be checked prior to the switch statement. I've modified my original program that I posted at the top of this thread. What needed to be... |
Forum: C++ Mar 17th, 2008 |
| Replies: 2 Views: 771 Thanks again. After posting this question, re-reading it, I sort of then realised that the missing argument had to be 'hardcoded' or be a 'string literal' at the definition. Probably the point of... |
Forum: C++ Mar 17th, 2008 |
| Replies: 5 Views: 52,415 Thank you very much, this has certainly cleared things up. In a way, I'm glad I came across this problem, hopefully it won't catch me out again, when progressively compiling. |
Forum: C++ Mar 17th, 2008 |
| Replies: 5 Views: 52,415 I'm self studying from the book, C++ Primer Plus Fifth Edition, by Stephen Prata. The following relates to Chapter 13, Page 699, Programming Exercise #4. One task is to write the derived class... |
Forum: C++ Mar 17th, 2008 |
| Replies: 2 Views: 771 I'm self studying from the book, C++ Primer Plus Fifth Edition, by Stephen Prata. The following relates to Chapter 13, Page 699, Programming Exercise #4. One task is to write the derived class... |
Forum: C++ Feb 29th, 2008 |
| Replies: 7 Views: 945 Oops straight back at ya.......lol |
Forum: C++ Feb 29th, 2008 |
| Replies: 7 Views: 945 I think you mean when i is set to 6 it will fail, thus 5 iterations.
In relation to the original question, I would use a while loop with the test condition checking against the ever decreasing... |
Forum: C++ Feb 29th, 2008 |
| Replies: 23 Views: 1,977 You still need to call your function from main(). In main, simply initialise and assign three double variables and pass them into your function.
In main() something like this cout << mpg(d1, d2,... |
Forum: C++ Feb 29th, 2008 |
| Replies: 23 Views: 1,977 You need to at least write a main() program, that is the only way you will be able to test your mpg function. |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 Try it in a program........see what happens.... |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 Ok, here's the formula:
miles travelled / (size of tank - gallons left) = mpg.
mpg is miles per gallon.
miles : 1000
size (gallons) : 60
left (gallons) : 10
1000 / (60-10) = 20 mpg. |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 Ok, I can see where you are confused and I apologise accordingly. I re-read your initial first post and I skipped the bits about the information to be input being 1. size of tank, 2. gallons left... |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 It's the same function, you haven't made any changes.
By the way, in the context of your function the variable 'numberofmilest' first needs to be initialised as a double.
Have you tested this... |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 Do you notice in your function that you are passing in three arguments. To work out miles per gallon, you only need two arguments (miles and gallons). Do the calculation in the function (using... |
Forum: C++ Feb 28th, 2008 |
| Replies: 23 Views: 1,977 Think of it this way. You have two known pieces of information (gallons used and miles travelled), that is all you know. The third piece is what is calculated and is the purpose of the function -... |
Forum: C++ Feb 28th, 2008 |
| Replies: 5 Views: 1,369 Thanks everyone, much appreciated. |
Forum: C++ Feb 27th, 2008 |
| Replies: 5 Views: 1,369 Thanks all for responding, very much appreciated and it's certainly cleared the air for me. I've had to go back a chapter and re-read up on implied constructor conversions. I'm now left with this... |
Forum: C++ Feb 27th, 2008 |
| Replies: 5 Views: 1,369 Hope someone can clarify. I'm self-studying and my question relates to Programming Exercise # 2, Chapter 12, C++ Primer Plus Fifth Edition (pg. 629). I completed the exercise and achieved the... |
Forum: C++ Feb 21st, 2008 |
| Replies: 6 Views: 659 There is no need to initialise and declare the return value, in this case. It's returned directly without first assigning it to a variable. If you wanted to, you could initialise and assign to a... |
Forum: C++ Feb 5th, 2008 |
| Replies: 9 Views: 729 |
Forum: C++ Feb 3rd, 2008 |
| Replies: 2 Views: 835 I'll give you one thing, you've got more front than Myers (substitute 'Myers' for any major department store in your area) but maybe that's just me being cynical.
What type of program are you... |
Forum: C++ Jan 31st, 2008 |
| Replies: 5 Views: 3,147 Thank you all. This is now resolved. I fell victim to not reading the question properly. |
Forum: C++ Jan 31st, 2008 |
| Replies: 5 Views: 3,147 That is what I thought. To recap:
Move add(const Move &m) const;
// this function adds x of m to x of invoking object to get new x,
// adds y of m to y of invoking object to get new y,... |
Forum: C++ Jan 31st, 2008 |
| Replies: 5 Views: 3,147 I'm learning C++ from C++ Primer Plus, 5th Edition, and have come across the following problem.
The following class declaration is given as part of the question:
/*
Name: move.h
... |
Forum: C++ Jan 30th, 2008 |
| Replies: 8 Views: 1,918 I'm not really following the point of this thread. I can't see what the problem is. (other than a cranky professor) At the end of the day, you have to hand in your assignment and no doubt it's the... |
Forum: C++ Jan 29th, 2008 |
| Replies: 1 Views: 1,156 It seems like this is an ambitious project or assignment for someone who doesn't understand the basics of classes. I would have thought your class (as in school) would have eased you into this and... |
Forum: C++ Jan 28th, 2008 |
| Replies: 9 Views: 950 What did you do to resolve the problem? |
Forum: C++ Jan 28th, 2008 |
| Replies: 8 Views: 750 eesti44 it appears we're working from the same book, C++ Primer Plus, 5th Edition, and at the same chapter doing the programming examples. I've just completed this particular exercise and it gave... |
Forum: C++ Jan 28th, 2008 |
| Replies: 5 Views: 2,543 Thank you once again, I quickly added a blank int main() function and it compiled without error. I shouldn't forget this gotcha in future.
ps. I probably should have created a new thread for my... |
Forum: C++ Jan 28th, 2008 |
| Replies: 5 Views: 2,543 Thank you, how did I not see that.
I'm now getting another compiler error indicating this [Linker error] undefined reference to `WinMain@16' .
From another editor, Programmers Notepad,... |
Forum: C++ Jan 27th, 2008 |
| Replies: 5 Views: 2,543 Further, when I combine these two files into one file, for ease of compilation, I get the same compiler error message. So I suppose it's not related to a multiple file thing. |
Forum: C++ Jan 27th, 2008 |
| Replies: 5 Views: 2,543 Hope someone can help. I'm self-studying from C++ Primer Plus, 5th Edition. I'm having trouble working out why the following two files will not compile. I'm using Dev-C++, under Windows Vista.... |
Forum: C++ Jan 26th, 2008 |
| Replies: 5 Views: 698 Check your for line, there's an additional semi-colon.
numbersuffix is not declared, consider including string or cstring headers (one or the other).
Not sure why window.h is included, it's... |
Forum: C++ Jan 17th, 2008 |
| Replies: 1 Views: 1,313 At a glance I'd say that if the variable 'day' is evenly divisible by 5 then branch off to your 'theNextGeneration()' function.
Another way, which was also indicated was to increment day by 5 thus... |
Forum: C++ Dec 30th, 2007 |
| Replies: 16 Views: 3,064 I'd guess that you should be able to determine if it's right or not and I'm suspecting you're guessing it's not.
I'd suggest removing the cout statements from the for loops of the assignment... |
Forum: C++ Dec 30th, 2007 |
| Replies: 16 Views: 3,064 This works if you don't mind the newline right from the get go.
if (i % 10 == 0)
cout << endl;
cout << alpha[i] << "\t"; |