Forum: C++ 3 Days Ago |
| Replies: 3 Views: 153 A. please put code inside code tags, that makes it more readable.
B. In answer to your question, I'd ask you to work it out by hand. When i is 1, what is the index v_in and v_out? When you... |
Forum: C++ 9 Days Ago |
| Replies: 6 Views: 326 Put a counter in the loop. Display the results before the function returns, or pass it back as reference parameter. |
Forum: C++ 9 Days Ago |
| Replies: 6 Views: 326 Proper indenting would help you find the error.
while (!found && first <= last)
{
middle = (first + last) / 2; // Calculate midpoint
}
if (array[middle] == value) // If value is found... |
Forum: C++ 10 Days Ago |
| Replies: 6 Views: 326 Look at the order you are using the search functions.
You call the function, looking for a fixed number.
You then ask the user to enter a search value.
You then test the result of your search, for... |
Forum: C++ 11 Days Ago |
| Replies: 1 Views: 182 How about:
while( INSTREAM.getline(line,500) )
{
OUTSTREAM << counter << line;
counter++;
}
You can search on DaniWeb why the eof( ) usage is not advised. |
Forum: C++ 11 Days Ago |
| Replies: 10 Views: 494 I get no errors on that line, but several other compiler errors and warnings do come up (Visual C++ 2008)
Have you in fact posted the latest version of your code that is giving you problems? Have... |
Forum: C++ 17 Days Ago |
| Replies: 2 Views: 181 I'm surprised you get even that. Firstly, if you're getting warnings from your compiler, pay attention to them and fix the problems.
#1 - it's int main( ) , not just main( )
#2 - quotatot is... |
Forum: C++ 25 Days Ago |
| Replies: 17 Views: 542 You should check where the program crashes, and read the error message(s).
Check your arguments closely - what's being used here, and what is being used without having a value assigned?
... |
Forum: C++ 25 Days Ago |
| Replies: 3 Views: 178 First, the code would be clearer if your variable names better expressed what they were.
What's "total"? The input of distance driven should be "miles", not "mpg". mpg = miles / gallons better... |
Forum: C++ 25 Days Ago |
| Replies: 2 Views: 199 What's the largest value that can be stored in a long int?
How does that limit compare to the value you're trying to stuff into a long int? |
Forum: C++ 27 Days Ago |
| Replies: 2 Views: 167 results[0]= x * sin (x);
x is an array - it cannot be used as the operand of a multiplication nor as the argument to sin( ).
Did you mean to say results[i]= x[i] * sin (x[i]);? |
Forum: C++ 27 Days Ago |
| Replies: 2 Views: 142 Actually, it does make a difference. The declaration outside of main( ) is globally visible and modifiable. This is generally to be avoided, especially in beginning programs, as it may cause the... |
Forum: C++ 27 Days Ago |
| Replies: 1 Views: 195 switch blocks are not good for doing range based decision making. You have to be able to do exact matches to integral types, which is often, as you surmise, way too much work.
Use if...else if...... |
Forum: C++ 27 Days Ago |
| Replies: 10 Views: 346 Your new function, which still has the { } problem jonsca pointed out, will return immediately after the first number is read in, depending on whether it meets the 10-500 test or not.
You should... |
Forum: C++ Oct 23rd, 2009 |
| Replies: 4 Views: 271 Do you have a pencil and a piece of paper handy?
This is C++. |
Forum: C++ Oct 22nd, 2009 |
| Replies: 4 Views: 272 You need to write a couple of hand scoring functions. You don't look for all possible combinations, but look at a player's hand and determine what, if any, of the poker hands it constitutes.
... |
Forum: C++ Oct 21st, 2009 |
| Replies: 3 Views: 482 To read just 5 characters at a time to your array, you could use getline( ).
Make your array size 6 to allow for the null terminator at the end of a string, then
char arr[6];
//open your... |
Forum: C++ Oct 21st, 2009 |
| Replies: 4 Views: 271 I would do a search of the daniweb c++ forum and find this problem discussed many, many times.
( I wish profs would be a bit more creative and come up with some new assignments.) |
Forum: C++ Oct 18th, 2009 |
| Replies: 5 Views: 264 Hmm, bet you made the file in notepad and named it "test.txt", and Vista added the other .txt. Or VS might have done the same thing.
That's why I like to set my systems to display the file... |
Forum: C++ Oct 18th, 2009 |
| Replies: 5 Views: 264 What compiler/IDE are you using? That would help us to tell you where the input file should be located. Are you running this from the IDE or directly in a command window? |
Forum: C++ Oct 18th, 2009 |
| Replies: 1 Views: 193 Long time ago I used this article (http://msdn.microsoft.com/en-us/magazine/dvdarchive/cc301454.aspx)as a reference to do such.
Unfortunately, it seems the supporting code is not available at... |
Forum: C++ Oct 18th, 2009 |
| Replies: 1 Views: 279 Here's your code, translated in to C++.
#include <fstream>
#include <iostream>
using namespace std;
void READFile(char* filename)
{
int num; |
Forum: C++ Oct 18th, 2009 |
| Replies: 3 Views: 402 |
Forum: C++ Oct 18th, 2009 |
| Replies: 4 Views: 214 Read the problem thoroughly. List what you know, what's to be input, what you're to do with it.
Then start listing the steps to accomplish the task. Voila, you're done. |
Forum: C++ Oct 17th, 2009 |
| Replies: 4 Views: 422 RTE, I think you're reading too much into this. The airline reservation/seating problem is a common assignment in beginning programming course, as evidenced by the many times it's come up here. |
Forum: C++ Oct 17th, 2009 |
| Replies: 4 Views: 422 Read the full assignment. It should all be there. |
Forum: C++ Oct 17th, 2009 |
| Replies: 2 Views: 176 You could pass the username and password arrays (or the single array of user objects when you make a class) to the checkDetails( ) function. That way you don't have the arrays in global space... |
Forum: C++ Oct 17th, 2009 |
| Replies: 4 Views: 217 Yes, you could use a loop to print only up to 22 characters. Be sure to first test the length of the actual string content, and limit your loop to 22 or the string length, whichever is less. |
Forum: C++ Oct 17th, 2009 |
| Replies: 3 Views: 180 So, your function must:
1. Display the menu. What are the options in this program?
2. Ask the user to make a selection from the options available. Usually you will take this in as either a... |
Forum: C++ Oct 17th, 2009 |
| Replies: 4 Views: 217 I think a better approach would be just use getline to grab all of a line into a large string, then print out the first 22 characters that appear (or less if the line's not that long.)
You can... |
Forum: C++ Oct 16th, 2009 |
| Replies: 1 Views: 181 Please use this big white space to ask a question. If you read the sticky threads at top, you'll find useful information on how to ask questions here.
It looks like you're writing in C, this is... |
Forum: C++ Oct 16th, 2009 |
| Replies: 3 Views: 388 Please read the sticky threads about how to ask questions.
Mainly, please put your code inside code tags so it will be more readable, like
your code goes here
Big problem with your second... |
Forum: C++ Oct 15th, 2009 |
| Replies: 5 Views: 548 For your array, if the problem is given as a set size, just declare a local array, as you show int plate[10][10]; for example.
If no specific info is given for initial state of interior nodes,... |
Forum: C++ Oct 14th, 2009 |
| Replies: 5 Views: 223 YES, that was a typo
Should read
for( c = 0; c < 5; c++ )
(walks away with embarrassed look) |
Forum: C++ Oct 14th, 2009 |
| Replies: 5 Views: 548 What I believe the problem is asking you to do is set up the 2D array.
Read in the temperatures along the edges (is the temperature the same all along an edge or does it vary along the edge,... |
Forum: C++ Oct 14th, 2009 |
| Replies: 5 Views: 223 Is your array declared as 5 columns or as 6? It makes a difference in the indexing you use.
Are you using the row index as the student ID? I don't see input for IDs.
Remember that the maximum... |
Forum: C++ Oct 13th, 2009 |
| Replies: 2 Views: 212 Well, I think an elegant solution would be a loop that iterates from -4 to +4, inclusive. Within that loop is another that uses the absolute value of the loop counter to print out the numbers and... |
Forum: C++ Oct 13th, 2009 |
| Replies: 3 Views: 261 Why are you doing two input actions in the loop?
The first, in the while condition, reads the word and stops at the newline. The getline will read and discard the newline, storing an empty string to... |
Forum: C++ Oct 12th, 2009 |
| Replies: 3 Views: 380 Sure you could modify during runtime. And make allowance to store the parity bit(s) as well.
Say you want to store a byte, plus a parity bit. Allocate an array of 9 char's (unsigned, if you want,... |
Forum: C++ Oct 12th, 2009 |
| Replies: 3 Views: 380 Depends on how easy you want to access the bits, and how you get the data.
You could store the data as an unsigned char, and access each bit using masks. That easily handles single bytes.
You... |