Forum: C++ 1 Day Ago |
| Replies: 2 Views: 113 Are necessary headers #included prior to the lines in question?
The functions calls shouldn't have the [] part.
Do your headings have the curly-brace part?
Your code may be long, but you've... |
Forum: C++ 1 Day Ago |
| Replies: 7 Views: 125 My assistance has been subpar tonight. Try this:
void loadFileToArray (string namesArray[], double gradesArray[][4], int &numberOfStudents)
{
string filename;
ifstream inputDataStream;
... |
Forum: C++ 1 Day Ago |
| Replies: 7 Views: 125 Ah! Separate lines for the names and the grades! I stand corrected. My crystal ball file looked like this:
5
foo 95 84 72 87
bar 91 77 82 63
baz 75 63 66 42
qux 50 49 33 58
moo 92 95 97 91
noo... |
Forum: C++ 1 Day Ago |
| Replies: 7 Views: 125 I don't have this file or some other one that apparently works for you. From what I was tinkering with, I would be surprised with it having ever worked correctly. And since I haven't seen the input... |
Forum: C++ 1 Day Ago |
| Replies: 7 Views: 125 You've got nested loop issues.
After you get the line, the line is got. Reading "the rest of the line" will be problematic.
You should check for success when you attempt to read from the file.... |
Forum: C++ 1 Day Ago |
| Replies: 18 Views: 221 I have no idea what you are entering to the program. Any hints? |
Forum: C++ 2 Days Ago |
| Replies: 2 Views: 107 It sounds like you may be confused as to how an array/C-style string is passed to a function in C and C++. In the example, the array for a C-style string str is declared.
/* strcat example */... |
Forum: C++ 4 Days Ago |
| Replies: 3 Views: 129 Keep track of the index of the highest value while taking input. Initialize to the first element:
int hi = 0;
When you find a new highest value, capture the index:
if ( votes[i] >... |
Forum: C++ 4 Days Ago |
| Replies: 9 Views: 149 Really? This isn't reading all of the data into element zero:
int numCan = 0;
int totvote = 0;
// ...
for ( i = 1; i <=5; i++ )
{
inFile >> candidates[numCan] >>... |
Forum: C++ 4 Days Ago |
| Replies: 9 Views: 149 First, get the input right. Then yes, adding is pretty simple. |
Forum: C++ 4 Days Ago |
| Replies: 9 Views: 149 Maybe if both existed and they were used in a way that had meaning, like i (kinda). |
Forum: C++ 4 Days Ago |
| Replies: 5 Views: 165 The difftime (http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.12.2.2) function returns the difference expressed in seconds as a double. |
Forum: C++ 4 Days Ago |
| Replies: 9 Views: 149 Read input, then print it? |
Forum: C++ 11 Days Ago |
| Replies: 5 Views: 209 You seem to be using a lousy code editor and have "fancy quotes" instead of the plain variety. After that you'll get more syntax errors to clean up, like this
int calc_bonus(int sales){
You need to... |
Forum: C++ 14 Days Ago |
| Replies: 11 Views: 429 That happens to be true for the garden variety PC of today, but it is not true as a generic statement. |
Forum: C++ 15 Days Ago |
| Replies: 6 Views: 324 #include <iostream>
#include <fstream>
#include <cstdlib>
int main()
{
std::ifstream file("reg.txt");
char text[80];
while ( file.getline(text, sizeof text) )
{ |
Forum: C++ 17 Days Ago |
| Replies: 5 Views: 304 |
Forum: C++ 18 Days Ago |
| Replies: 5 Views: 321 http://groups.google.com/group/comp.lang.c/browse_thread/thread/2aaf5360b08c89a9/1000b1f7fb33ea53?ie=UTF-8&q=float+promoted+double+function+group%3Acomp.lang.c&pli=1 |
Forum: C++ 18 Days Ago |
| Replies: 1 Views: 172 for (int i=1;i<=8;i++)Don't you mean this?for (int i=0;i<8;i++) |
Forum: C++ 20 Days Ago |
| Replies: 3 Views: 280 I think this thread hits on it:... |
Forum: C++ 20 Days Ago |
| Replies: 3 Views: 235 #include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "RAND_MAX = " << RAND_MAX << "\n";
return 0;
} |
Forum: C++ 20 Days Ago |
| Replies: 3 Views: 280 I don't think you even want the array, but instead are after this?
inFile.open(file); |
Forum: C++ 20 Days Ago |
| Replies: 3 Views: 146 Match your prototypes with function signatures. |
Forum: C++ 20 Days Ago |
| Replies: 4 Views: 190 You can't pass an array by value ("the whole array"). When you "pass an array", you instead pass a pointer to the first element. What I believe you are doing is writing to a random memory location... |
Forum: C++ 20 Days Ago |
| Replies: 4 Views: 190 Do you know why you're trying to use an array of pointers to char instead of an array of char?
main(){
const int max_chars =100;
int length= 0;
char* letters[max_chars + 1];
... |
Forum: C++ 21 Days Ago |
| Replies: 2 Views: 175 Lose the semicolon:
#define CAPACITY 128;
[edit]Avoid expressions like this:
i=(i++)%CAPACITY
http://c-faq.com/expr/ieqiplusplus.html |
Forum: C++ 21 Days Ago |
| Replies: 3 Views: 338 Another way would be to write this as a function. If any character does not match, you can break the loop early and return a value indicating the "strings" do not match. If all characters do compare... |
Forum: C++ 21 Days Ago |
| Replies: 4 Views: 243 Another way of reading "7 times per line" is "output a newline every 7 times". You could do this with a separate counter (in the same loop though!) that counts to 7, outputs a newline and then is... |
Forum: C++ 24 Days Ago |
| Replies: 5 Views: 360 time is a reserved identifier. |
Forum: C++ 25 Days Ago |
| Replies: 5 Views: 328 Huh?
If you're trying to open the file for input, you use this bit here:
ifstream inputFile;
Open the file and read it? |
Forum: C++ 25 Days Ago |
| Replies: 2 Views: 217 How about a final else?
And don't use the comma here:
else if (numtick >100,000) |
Forum: C++ 26 Days Ago |
| Replies: 20 Views: 423 Related:
http://parashift.com/c++-faq-lite/input-output.html#faq-15.4 |
Forum: C++ 26 Days Ago |
| Replies: 6 Views: 436 Well, choose your poison: multiple passes of the same file, or a single read with a buffer. Both are relatively simple, I'd recommend just examining what's there. Experiment a bit. Learning to code... |
Forum: C++ 26 Days Ago |
| Replies: 6 Views: 436 I suppose you could read the file to count the lines and then back up and only print the last 10.
Why the extra condition now?
Why don't you give the coding a shot first? |
Forum: C++ 26 Days Ago |
| Replies: 6 Views: 436 I'd just read all lines of the file into a circular buffer with 10 strings, each containing a line. When you get to the end of the file, you will have the last 10 lines stored.
#include <iostream>... |
Forum: C++ 27 Days Ago |
| Replies: 20 Views: 423 Well, if you don't get an integer because the user didn't enter a valid one, then "(x>0)" makes no sense either. You can do it your way by recognizing input failure and cleaning up the input stream.... |
Forum: C++ 27 Days Ago |
| Replies: 20 Views: 423 I think the basics are here:
http://www.daniweb.com/tutorials/tutorial71858.html |
Forum: C++ 27 Days Ago |
| Replies: 20 Views: 423 My usual advice is to always read all user input as a string. If you want a numeric value, attempt to perform a conversion. If the conversion fails, issue a message or something; otherwise you... |
Forum: C++ 28 Days Ago |
| Replies: 12 Views: 370 You're going to return from main in one of two places:
int main ()
{
int number;
int counter = 0;
int flags = 1;
bool flag_none = true;
bool fag_yes = false;
cout << "Enter a number,... |
Forum: C++ 28 Days Ago |
| Replies: 12 Views: 370 The following code is unreachable:
if (counter < 7 == true)
{
cout << "Number " << counter << " is between 10 and 500" << endl;
cout << "Number " << counter << " is not flagged. " << endl;
}... |