Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Sorry, that was my mistake - I failed to close the two open brackets. It should go as follows:

for (int i = 0; i < 8; i++) {
                      if (a[i] == goalTotal) {
                          cout << endl << "Player Wins" << endl;
                          win = true;
                          break;
                      }
                  }
jankeifer commented: he's awesome! +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What you need to do is have the CGI script actually generate an HTML page, rather than simply printing back plain text.

Can you post the relevant code (using CODE tags if you please)? It would make it much easier to discuss this if we could see the program in question.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, OK, I see the issue now. On that particular line of code, you consistently mistyped parsedLine as parsedline (with the lowercase 'l') and that's what it is complaining about - as far as the compiler is concerned, parsedLine and parsedline are completely different identifiers.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Since you are already testing for wins, we can use that to simplify the loop exit. First we'll add a Boolean variable named win and initialize it to false:

bool win = false;

Then we'll simplify the test for winning:

for (int i = 0; i < 8; i++) {
                      if (a[i] == goalTotal) {
                          cout << endl << "Player Wins" << endl;
                          win = true;

Finally, we change the conditional of the do/while() loop:

while(!win);

Try that and see if it works.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, sorry, I was convinced that was the source of the issue.

Could you post the exact error message, please? There may be some detail in it that would give the cause for it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Try taking the second for() loop out of the main() function, and put it into a new function starting with the line:

int sum(int* A)

and after the end of the for() loop, add a line

return total;

Now, where the for() loop was, put the following line:

total = sum(A);

This will actually call the function you've written.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

First off, you need to edit your post so that the code is in [CODE] tags - the forum software does not retain indentation, so the code is unreadable unless you use the tags.

Second, just what do you mean you need to 'change it to function type'? Do you need to break the program into more than one function, or what?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Are you sure that it is line 45 of the main.cpp file? AFAICT, the problem is on line 45 of playlist.cpp, where you have the print() function incorrectly associated with class 'contact'.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What is happening is that, because the header file is being included in both of the compiled files, the two globals are indeed being re-declared, once in each file. You need to change the header so that both are declared as extern :

#ifndef MAIN_H
#define MAIN_H 1

extern int a;
extern int b;

#endif

Then you need to actually declare the variables in either main.cpp or secondary.cpp (but not both):

#include "Main.h"
#include <iostream>
void Engine();

int a;
int b;

int main()
{
    b = 10;
    a = 5;
    std::cout << a << b;
    Engine();
}

The declaration in main.cpp is the actual declaration; the one in the header is just to allow other files to know that they exist.

Note also the use of include guards, which are to prevent a different sort of redefinition issue.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I would recommend moving the file open and close operations out of the loop; even if it were working, the way you are repeatedly opening the file causes the file position to get reset each time, with the result that each number would overwrite the previous, causing only the last number to be in the file at the end.

Also, opening, closing and writing to files are fairly expensive operations, relatively speaking, and it actually makes more sense to have two separate loops - one for collecting the data, and a separate one for writing to the file. While this may seem like an inefficient approach, it is actually a lot more efficient than making separate file writes, as writes made in quick succession will generally be buffered and end up written together, something that won't happen if you keep opening and closing the file.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The '[20]' values (note the square brackets, as opposed to parentheses, that's important) are the array sizes. When you write

char myArray[20];

what you are declaring is an array of size 20. When you then write

char ch = myArray[4];

you are then assigning the 5th value in the array (not fourth - array indices start at 0) to the character variable ch .

The reason you use character arrays for the character strings is because a plain char value can only hold one character at a time. So if you need to store the name 'John', you need to have an array capable of holding each of the letters in the name, plus one for the NULL Marker (a special character used to indicate the end of the string). By declaring the array to have size 20, you are giving it enough room for most personal names.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Please edit your post by putting [code] tags around the code sample. The forum software does not retain indentation by default, so with the code tags, it is very difficult to read the program.

EDIT: I should have been paying closer attention when I replied. The real advice should have been not to hijack old threads.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Microsoft Support KB article 99261 gives two methods of clearing the Windows console in C++: using system("cls"); and using a function which, while complicated, should be more or less drop-in: the most difficult part of it is the need to get the console handle, which can be gotten from GetStdHandle().

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);

    cls(console);

Mind you, if you're using Managed C++ (or any of the .Net languages), you would also have access to the Console.Clear() method.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

If you don't mind me asking, why are you using C-style strings for the username, password, etc., when you've already used a string for the user variable? Wouldn't using a C++ style string be much easier?

Also, I would recommend breaking your program up into separate functions, especially the login operation, which you actually have in two different places that I can see.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While my point had more to do with there being a problem with your VC++ setup rather than a suggestion to switch compilers, you might find it worth learning about GCC as an alternative approach (and it is often useful to have two different compilers to use for comparison tests). You can get the MinGW port of GCC for Windows, which gives you the command-line compiler and toolset. Conversely, you could get the Code::Blocks IDE, which comes bundled with MinGW and is a lot easier to get started with (make sure you get the version marked 'mingw-setup'). I would recommend eventually learning to use the command-line tools, as it clarifies a lot about how compilers really work, but if you're just starting out, using an IDE is a lot easier.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Interesting. I was able to compile and run the program correctly under GCC, which leads me to think that the problem is with your project file rather than the code itself. I may be wrong, however...

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Not quite. What setw() does is not indent the text; rather, it sets the field width of the text, with the right side of the text by default going to the rightmost column of the field (this is called 'right justified' text; you can explicitly set it to left-justify using the left manipulator). When you set the field size less than the size of the actual text going into the field, the text will in effect start at the beginning of the field and stick out past the end of the field.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Rather than complaining about what you don't know, let's look at what you do know, and start with that.

  • You need to write a main() function.
  • You need to define a structure type that holds a person's contact information. An example of what this should look like was given to you by the teacher.
  • You need to declare at least one variable of said struct type. Again, an example of this was included in the sample code.
  • You need to present a menu for the user to choose from.
  • You need to be able to read in a person's contact information from the console, and put it into the Contact structure.
  • You need to put the menu in a loop so that it repeats the menu.

All of these things should have been covered in your classwork. Is there any part of it you are having trouble with?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, to start with, since you are using more or less the same data members in both versions of the qa class, let's apply some basic reusable design by combining the two related classes into one, and separating this new class from the main program files. This will allow you to ensure that the two classes don't diverge in some way that would break them both, and make it less confusing for anyone trying to read these programs later. Since you are using an IDE that has code completion, let's write out the new class name in full as QuizAnswer .

Second, I notice you are including the <string> header, but don't seem to be using the string class itself. If you're allowed to use strings for this project, then I would recommend doing so, as it would simplify the data reading and writing if you didn't have to worry about the string lengths all the time the way you do with C-strings.

quiz.h

#ifndef QUIZ_H
#define QUIZ_H 1

#include <iostream>
#include <fstream>
#include <string>


const unsigned OPTION_COUNT = 4;

class QuizAnswer
{
    std::string question;
    std::string option[OPTION_COUNT];
    int answer;

public:
    void getques()
    {
        std::getline(std::cin, question);
    }

    void getopts();

    void getans()
    {
        std::cin >> answer;
        std::cin.ignore();
    }

    void write(std::ofstream& output);
    void read(std::ifstream& input);

    void putques()
    {
        std::cout << question << std::endl;
    }

    void putopts();
    int putans();
};

#endif

quiz.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "quiz.h"


void QuizAnswer::getopts()
{
    for (unsigned i = 0; i < …
rajatchak commented: Just Awesome!! Mastermind!! +1
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I believe this will fix an number of issues with the code:

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cstdlib>

using namespace std;

void setColor(int color);

int main()
{
    const int SIZE = 5;
    double response[SIZE] = {0};
    double responseTotal = 0,
           responseAverage = 0,
           responseHigh = 0,
           responseLow = 0;

    setColor(0x1F);

    cout << endl << setw(16) << right << " " << "***********************************"
         << endl << setw(16) << right << " " << "*     Cafeteria Food Survey       *"
         << endl << setw(16) << right << " " << "***********************************"
         << endl << endl << endl
         << "  " << "Enter a rating between 1 and 10:  1=AWFUL 10=EXCELLENT"
         << endl << endl;

    for(int index = 0; index < SIZE; index++)

    {
        cout<< endl << "  " << "Rate Cafeteria Food (scale 1 to 10): ";
        cin >> response[index];

        while(response[index] <= 0 || response[index] > 10)
        {
            cout << endl << "  " << "\a\a\aError: Specify a number within a valid range. ";
            cin >> response[index];
        }
    }


    // Display the contents of the array
    setColor(0x2F);
    cout <<endl << setw(7) << right << "Rating" << setw(12) << right << "Frequency" << endl << endl;
    for(int index = 0; index < SIZE; index++)
    {
        cout << setw(4) << right << response[index]
             << setw(6) << ' '
             << setfill('*') << setw(response[index]) << left << '*'
             << setfill(' ') << endl;
    }

    // Display Ratings Average
    for(int index = 0; index < SIZE; index++)
    {
        responseTotal += response[index];
    }

    responseAverage …
WaltP commented: And yet another free code post, with no explanation what the fixes are to boot! Courtesy of the DaniWeb Free Homework Service. -4
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Please, be patient; not everything gets an answer right away, that's just the nature of these fora.

Of the three operations, the easiest is searching; however, you would need to have more information passed to the function than just the list of contacts and the number of contacts, you'll need the name you are searching for as well. Something like this for the function prototype:

void findbyName(const Person list[], int size, string name);

For the function itself, the easiest solution for a short, unordered array like this is just a brute-force linear search, using a for() loop through all the items until you reach the last one or you find a match against list.name .

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
for(int i = 0x21; i <= 0x7E; i += 6)
        {
            cout << setw(6) << static_cast<char>(i) << " = " << setw(3) << i;
            cout << setw(6) << right << static_cast<char>(i + 1) << " = " << setw(3) << i + 1;
            cout << setw(6) << right << static_cast<char>(i + 2) << " = " << setw(3) << i + 2;
            cout << setw(6) << right << static_cast<char>(i + 3) << " = " << setw(3) << i + 3;
            if ((i + 4) < 0x7f)
            {
                cout << setw(6) << right << static_cast<char>(i + 4) << " = " << setw(3) << i + 4;
                cout << setw(6) << right << static_cast<char>(i + 5) << " = " << setw(3) << i + 5;
            }
            cout << endl;
        }
    }

But i was not able to understand this loop. Can you please explain it step by step, that will be very grateful of you. You see it differs from my loop a lot.

Is there any table you can show me regarding 0x21, 0x7E? And why in each loop i is incremented by 6? And the why those 4 cout statments. I think as long as i don't understand that Interrupt values(I am not sure, if they are called so), i may not be able to understand this loop & same goes for that if statement too.

Oops, I meant to explain about the hex values earlier, but forgot. Values beginning with '0x' are hexadecimal value, that is, …

PrimePackster commented: This explained a lot for me +0
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What is timeFactor for, and under what circumstances is it less than or equal to zero?

Also, have you considered making this part of the AI part of the enemy objects themselves, rather than part of the overall code? (I am assuming that Enemy is a class rather than a structure).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

OK, let's see what we can do, using what is probably the most over-used example for this. Imagine you have a class - it doesn't matter much what the class is for - that needs to keep track of how many objects there are in the class, and to allow the program to access the object count. An easy way to do this is to have a static integer counter and a static accessor for it. In the class declaration you would have:

class MyClass
{
private:
    static int counter;
    // other instance and class variables go here

public:
    MyClass();
    ~MyClass();

    static int getCount()
    {
        return counter;
    };
    // other methods go here
};

int MyClass::counter = 0;

Then in the c'tor and d'tor you'd have:

MyClass::MyClass()
{
    counter++;
    // the rest of the initialization goes here    

}

MyClass::~MyClass()
{
    counter--;
}

Finally, in your actual program you'd create some objects of the class and get the number of them that you created:

int main()
{
    MyClass* myObjectArray = new MyClass[SOME_NUMBER];

    std::cout << "The number of objects created is " << MyClass::getCount() << std::endl;

    delete[] myObjectArray;

    std::cout << "The number of objects remaining is " << MyClass::getCount();
}

The output should be the number objects created (equal to SOME_NUMBER in this example), and then the number of objects after deleting the array (which should be zero).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Might I suggest that it would make sense to separate the factorial operation into a separate function?

#include <iostream>


long factorial(long n)
{
    if (n < 1)
        return 1;
    else
        return (n * factorial(n - 1));
}

int main()
{
    int n;

    std::cout << "enter a number: ";
    std::cin  >> n;

    std::cout << "Factorial(n) = " <<  factorial(n);   
}

Just throwing in yet another variation on how to compute this. Not very efficient, to be sure, but perhaps the most interesting approach.

Regardless of how you compute it, the point is that by separating the factorial function from the main() code, you simplify both, and can avoid getting the code for one tangled up with the code for the other.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Ah, there it gets complicated, as static has a different meaning when applied to variables and methods in a class (as opposed to local variables in a function or method). Here, it indicates that the variable or method belong to the class, as opposed to the individual objects of that class. So, if you have a method declared static , as in this case, you would access it using the class name and the scope operator, rather than through an object variable's name. Static methods, in turn, cannot access instance variables, only class (static) variables, which again belong to the class as a whole and are, in effect, shared variables for all the members of the class.

BTW, don't ever use void main() ; while some compilers do allow it, the C++ standard specifically requires main() to be of type int .

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

As for the '.h' extension, the main issue is that when the C++ standard was introduced in 1998, they changed how many things worked. One of the key changes was the use of the namespace 'std' for most of the standard C++ library. Now, all of the stream I/O objects such as cin and cout would be part of the std namespace, which would make it easier for 3rd party library developers to design classes without worrying about conflicting with the standard library.
Because this (and other recent changes) broke the older code, it was decided that the new headers wouldn't have the '.h' extension, so that code which used the older headers would still use those versions of the headers. However, that was just for backwards compatibility; new code should always use the new headers, as they contain a number of improvements over the older headers.

Speaking of older software, if you have a choice, I would recommend replacing Dev-C++ with a newer IDE such as Code::Blocks. Dev-C++ hasn't been updated in six years and several problems in it were never fixed.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You can add [CODE] tags automatically by selecting your code with the mouse, then clicking on the [CODE] button at the top of the editing window. You can also add them manually simply by typing in [CODE] at the beginning of the code section, and [/CODE] at the end of the code section.

[CODE]
In the editor it will look like this,
[/CODE]

whereas when it is actually posted,

it will look like this.

BTW, I've edited my earlier post somewhat, so you may want to r-read it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What specifically is happening? Does it fail to compile? Does it freeze or crash? Does the initial "Enter a number" prompt print?

Regarding cin.get() , that is specifically for reading in a single character, which you don't seem to be doing anywhere here. In what way did it fail when you tried to use it?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Please put your code in code-tags in the future, to preserve formatting. Since the site does not preserve formatting by default, you should always put code samples between code tags.

#include <iostream.h>
#include <conio.h>

int main()
{  
    int number[5];
    cout<< " enter the number \n";

    for (int i=0;i<=5;i++)
    {   while (i!=$)
        {
         cin >> number[i];
        }
     }
     for (int i;i<='null';i++)
     { cout<< "number="<<number[i];
     }
        getch();
    return (0);
}

I see a few issues with this code as it is. First off, the 'special character' needs to be in single quotes. Second, and conversely, the 'null' should not be in single quotes, as it is not a character literal but a defined constant; also, it needs to be in all-caps (NULL). Third, because you are reading the input into an integer value directly, you'll never read in the dollar sign anyway, so the loop would never end.

BTW, what compiler are you using? Modern compilers should not accept the older <iostream.h> header, but should instead always use <iostream> (without the ".h" extension). On a related note, the <conio.h> is not standard, and while some modern compilers will support it, it is specific to the older DOS systems (which is not the same as the Windows Console).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Probably the easiest solution is to define a structure type (or a class, if you've gotten that far in your studies), and then declare a vector of that type. Something like the following should do:

struct Book
{
    long isbn;
    std::string title;
    std::string author;
    bool available;
};

std::vector<Book>;
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Here's code that I think will fix several problems at once:

#include <iostream>

using namespace std;


const int ARRAY_DIVISION = 16;

class SortedArray
{
public:
    SortedArray();
    void insert(int);
    void print();
private:
    int *sortedArray;
    int size;
    int totalSize;
};

SortedArray::SortedArray()
{
    size = 0;
    totalSize = ARRAY_DIVISION;
    sortedArray = new int[totalSize];
}

void SortedArray::insert(int inp)
{
    int i;
    size++;

    if (size == totalSize)
    {
        totalSize += ARRAY_DIVISION;
        int *temp = new int[totalSize];
        if (sortedArray != NULL)
        {
            for (i=0; i<(size-1) && inp > sortedArray[i]; i++)
            {
                temp[i] = sortedArray[i];
            }
            if (i < (size - 1))
            {
                temp[i] = inp;

                for ( i++; i < size; i++)
                {
                    temp[i] = sortedArray[i - 1];
                }
            }
            else
            {
                temp[size - 1] = inp;
            }

            delete[] sortedArray;
        }
        sortedArray = temp;
    }
    else
    {
        for ( i = size - 1; i > 0 && inp < sortedArray[i - 1]; i--)
        {
            sortedArray[i] = sortedArray[i-1];
        }
        sortedArray[i] = inp;
    }
}

void SortedArray::print()
{
    for(int i=0; i<size; i++)
    {
        cout << sortedArray[i] << " ";
    }
    cout << endl;
}

int main()
{
    SortedArray x;
    int inp = 0;
    do
    {
        cin >> inp;
        cin.ignore();
        x.insert(inp);
        x.print();
    }
    while(inp>=0);

    return 0;
}
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

You could improve the efficiency of the memory handling by reducing the number of times you have to copy the whole array. The best way to do this is to allocate the array, not to the exact size needed, but in multiples of some convenient value (16 is a good choice for this). You would need to add a second integer variable member to keep track of the total size of the array, as opposed to the used space.

This is just a refinement of the idea, however, and not actually necessary to make the class work.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Check the class definitions for Room and Monster, and make sure that there is a semi-colon after the last closing brace.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

When you apply sizeof() to a pointer, it does not return the size of the object pointed to; rather, it returns the size of the pointer itself. Thus, you will need to use size instead of sizeof(sortedArray) in the Print() method.

I would further recommend moving size into the class itself, rather than having it a global variable. That way, if you have more than one object of the SortedArray class, you wouldn't get a conflict in the sizes of the different arrays.

As a minor aside, you should be able to simplify the insert() method like so:

void SortedArray::insert(int inp)
{
	size++;
	int *temp=new int[size];
	for (int i=0;i<(size-1);i++)
		temp[i]=sortedArray[i];
	delete[]sortedArray;
	sortedArray = temp;   // since you are just copying the pointer, this should work
}

The way you had it before would also cause a memory leak, since you weren't deleting the temporary array; this approach neatly avoids that problem. However, I could add that you don't have any sort of destructor for the class, so the final value of sortedArray never gets reclaimed until the program closes.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I hate to sound like a broken record, but you really need to get your code formatting fixed. As inconsistent as it is now, it's almost impossible to read.

As for the problem, the issue is that you are passing the whole array to the sorting function, rather than just the part you mean to sort. Try the following at line 28:

selectionSort(arrayOne + 5, 5);

This uses what is called 'pointer arithmetic', and while you want to be very careful with it, it should offset the array to the section you want to sort.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I have noticed a few different things that you might want to fix about the program, aside from the problem you've mentioned:

  • The code formatting is very inconsistent; I recommend you be more careful about it. This page is a good reference for how to style your code in a readable manner.
  • You should only call srand() once, at the beginning of the program; by putting it in the randomizer function, you are calling it every time you use it, and if the calls are very close together, they may end up with the same seed (and hence the same 'random' number).
  • The five results* variables in your main() function are redundant; you can remove them entirely.
  • Since you want to be able to match the numbers regardless of the order they appear, you would be better off sorting the numbers first, then comparing them in order. This would simplify the comparison considerably, as you'd only need to check up to the number being sought.
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Could you please edit your previous post so that the code sections are in [CODE] tags? The forum software does not retain formatting by default, so the only way to be able to read the code clearly is with code tags.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Well, let's start with what you've already tried. Can you post your existing code, if any (using CODE tags, if you please)? Do you have any specific questions about how to do this?

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

No, that really isn't what they mean. What MandrewP was saying was that the type cast doesn't change the type of the original variable; it just returns a copy of it's value, changed to the new type. for example, if you have

double a = 17.23;
int b;

b = (int) a;

Then a itself is still a double ; it hasn't changed at all. Only the value passed to b was cast to the new type.

As for the actual problem with the int=>char conversion, you are still getting part of it backwards: you need to cast the value to the type it is being copied into, not the type it is already.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int a, choice;
    char b, choice2;
    cout << "Would you like to print the ASCII Table first? (Y/N)"<<endl;
    cin >> choice2;
    if(choice2=='y' || choice2=='Y')
    {
        for(int i = 0x21; i <= 0x7E; i += 6)
        {
            cout << setw(6) << static_cast<char>(i) << " = " << setw(3) << i;
            cout << setw(6) << right << static_cast<char>(i + 1) << " = " << setw(3) << i + 1;
            cout << setw(6) << right << static_cast<char>(i + 2) << " = " << setw(3) << i + 2;
            cout << setw(6) << right << static_cast<char>(i + 3) << " = " << setw(3) << i + 3;
            if ((i + 4) < 0x7f)
            {
                cout << setw(6) << right << static_cast<char>(i + 4) << …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Assuming I'm understanding this correctly, what you need to do is combine a regular for() loop conditional with the test for the end of the loop as you have it above:

for (int i = 0; (i < iterations) && (p != currentlist.end()); i++)
{
  // code goes here
}

The reason you need both is for the case where the list is shorter than the number of iterations.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Getting back to the code itself, I would strongly recommend separating the sorting operation into it's own function, which would let you test it separately from the input and output code. This would help narrow down the location of the problem. Something like this should do:

void bsort(double arrayOne[], int size)
{
    for (int i = 0; i < size; i++)
    {
        double currentMin = arrayOne[i];
        int currentMinIndex = i;

        bool needNextPass = true;

        for (int k = 1; k < size && needNextPass; k++)
        {
            needNextPass = false;
            for (int i = 0; i < size - k; i++)
            {
                if (arrayOne[i] > arrayOne[i + 1])
                {
                    double temp = arrayOne[i];
                    arrayOne[i] = arrayOne[i + 1];
                    arrayOne[i + 1] = temp;

                    needNextPass = true;
                }
            }
        }
    }
}

NOTE: this is not tested code. I simply modified what you already had into a stand-alone function; you'll still need to debug it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

There is an additional tool named apropos which allows you to search through the man pages for a given word or phrase.

As for networking, specifically, there are some excellent tutorials online for that, with Beej's Guide to Networking being one of the best-known and most respected. For information on the Linux libraries in general, you can try The Linux Documentation Project, which is set up to cover most of the major aspects of Linux as a whole. For external libraries such as Allegro or cURL, the best place to start is usually the website for the library itself.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

While WaltP may seem brusque, he's actually quite knowledgable; you'd do well to listen to him on this point.

As for how to format code, WaltP's earlier link (which I'll re-post here for you, in case you missed it) is an excellent primer on the subject This link here gives details on different approaches to indent style, with a specific style (Allman) highlighted. A broad search on indent style or brace style should turn up a plethora of information. One point to be made is that the specific style you choose is less important than being consistent, both with what style you use and in applying it; inconsistently formatting code can be as bad or worse than not styling at all.

If all else fails, you might also look into editing your code with an IDE that has an auto-indent feature. I have been using Code::Blocks a lot lately, and that comes with the Astyle tool (under Plugins). Visual C++ Express has a good auto-styler as well.

What editor or IDE are you using? Chances are, it already has support for auto-indentation, even if you don't know it.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

BTW, I noticed that you are using Allegro 4.2.2, rather than 5.0. Did you compile the Allegro libraries yourself, or get the binaries from some other source? If the latter, where did you get them?

If the libraries were compiled some time ago, using the QuickDraw libraries rather than Quartz, that could explain one of the warnings you got while running the program. I don't know how much it would impact the overall problem with linking, however.

Also, you might look to the Allegro Wiki for information, if you haven't already.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

What about structures? I mentioned that it would make it easier to work with the data, as you'd have only one array to manipulate, pass to the functions and so on. The version of the program I wrote, for example, used an array of the following struct:

struct Team
{
    int rank;
    std::string name;
    int yards;
    float yards_avg;
    int passyards;
    float pass_avg;
    int rushyards;
    float rush_avg;
    int points;
    float points_avg;
};

This makes it a lot easier to work with, and to keep track of both the data you are using and that which you aren't (when reading in the data, that is).

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

I see two major problems with the min/max code as it is now. First, when you attempt to call the function max_min_two_arrays , you did not give it's arguments; as a result, the function isn't actually getting called (it simpley returns the pointer to the function, which, since nothing is assigned on that line, goes into the ether), so the line of code doesn't have any effect.

The second is that, in the function itself, once you get the max and min values, you don't do anything with them.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

Without seeing the code for your main() function, my guess is that you are using soemthing like

cin >> ch;

to read in the character where the player chooses an option, correct? If so, you will want to clear the input buffer using cin.ignore() immediately after that. What is happening is that the newline after the character is still in the buffer, and you need to clear it before you can read in a new line.

Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

The first step, sadly, is to clean up your code formatting; as it is, it is inconsistent and hard to read.

The next step would be to have the code check for when the user chooses to exit. This can be done simply by testing the user input.

The third step is to actually deduce one token from the payer's tokens every time they play:

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{

    unsigned x, token=4;
    unsigned short playOn;

    srand(time(0));

    cout<<"\t********************************************************\n"
        <<"\t*              Welcome to slot machine.                *\n"
        <<"\t*  Would you like to play? (1 to play, 2 not to play)  *\n"
        <<"\t********************************************************\n\n";
    cin>> playOn;
    while(token!=0)
    {
        cout<<"You have "<<token<< " tokens\n\n"
            <<"Pull? (1 to pull, 2 not to pull)\n\n";
        cin >> playOn;

        // if they no longer want to play, exit the loop
        if (playOn != 1)
            break;

        // deduce one token to pay for the play
        --token;        

        unsigned short wheels[3]; //declare array of ints

        for(int x=0; x<3; x++)  //fill array with random numbers
        {

            wheels[x]=1+rand() % 10;
            cout<<wheels[x]<<" "; //print numbers in array

        }

        cout<<endl;
    }

    return 0;
}

Step three would be to work out how to detect matches and how much the payoff for each ought to be. My recommendation is to have a table which holds all of the winning outcomes, and compare the result with that table. As an example, you might have something like this:

unsigned short payoffTable[][][] = {{10, 10, 10, 1000},
                                    {9, 9, 9, …
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster

When WaltP spoke of counting line and using needing to use an integer for the array index, he was (I assume) speaking of the variable linecount , not the array itself. The array can, and probably should, be of type array of double ; but for any array, the indices should be type int (or a related integral type such as unsigned or long ). If you think this through, it makes sense that this would be the case, as you cannot access (for example) the 1.5th element of an array.

As for fgets() and sscanf() , the former is a function for reading a line of text from a stream up to a maximum size, while the latter allows you to parse a string into it's components. However, given that you are using the C++ <iostream> functions for your user input, I would recommend using the C++ equivalents, which are getline() and the stringstream class.

On a final note, which I'm sure WaltP will mention, using while(!input.eof()) without also testing for input.fail() is liable to cause your program to either loop indefinitely, or else overcount the number of lines by one.