![]() |
Need some C++ help
Hey guys...writing a program (or, trying to;)) for my CS class...I have it about 99% done, but I can't get one nagging detail right.
What I need to do is read data from a file into parallel arrays, which are declared as: Code:
string Brand[MAX_COMPUTER]; I tried something like: Code:
{ Any ideas? So close to done... Thanks in advance. PS: If anyone wants to whole code, just to see what I'm doing, I'll put it online. Also, if you need to understand the problem more, or I don't explain it clearly enough, you can read about it at http://www.cs.uky.edu/~ryan/CS215_F07/programs/1pgm.html |
Not sure, but I'm thinking check your array index limits at this point.
|
Got it figured out. What was happening with the original loop is that the variable count, declared as a short, would keep counting after reading the 10 entries from the file because, since it isn't entering the IF loops, it's not actually _reading_ from the file, so it continues forever. Actually, it continues until "count" reaches 32767, which is the upper limit of a short, then it rolls over to some negative value (-1 I think) and crashes the program with Memory Access Violations. Am now using "unsigned short count = 0" since the value of count since the value shouldn't ever go negative. Also, have the loop fixed. It is now:
Code:
unsigned short count = 0; |
I was just going to point out the logical error with your bounds check, which you've fixed. Not knowing how big MAX_COMPUTER was, I don't think I would have caught the other problem.
Ah, I do recall the good old days. Now I code in Ruby, where I don't have to worry about variable declarations. :) |
Um, anyone know how to control a Bubble Sort algorithm with a bool flag?
Code:
if (choice == 1) |
Oh god, I'm going back decades (before C, much less ++ :)), so I can't offer specifics. In general, if you can't use an expression such as "Do while BooleanFlag = False", or something similar, you can simply set up an outer "If" loop:
Swapped = False If Swapped = False ....your existing If loop logic... Swapped = True (when the swap is made...this should terminate the outer loop) Sorry I don't know C++, and my programming skills are rusty, but maybe this will get you thinking in the right direction... edited: sorry, I lose my indentations on the looping logic...hope it's still clear as mud:) |
All times are GMT -8. The time now is 04:33 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0
Copyright 2025 Pelican Parts, LLC - Posts may be archived for display on the Pelican Parts Website