NathanOliver 429 Veteran Poster Featured Poster

Well do you know what the formula for the fibonacci squence is? If not it is Fn = Fn-1 +Fn-2 where F0=0 and F1=1. so to get a fib number you have to take the previous number plus the number before the previous number. Can you see know how the code is working?

Grandiago commented: Thanks for the formula! Haha +0
NathanOliver 429 Veteran Poster Featured Poster

You should use a do-while loop instead of goto.

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

int main()
{
    int array[100], position, c, n;
    char ch;
    bool loopAgain = false
    do // do instead of A
    {
        cout<<"Enter number of elements:";
        cin>>n;

        cout<<"Enter "<<n<< " elements:\n";

        for ( c = 0 ; c < n ; c++ )
            cin>>array[c];

        cout<<"Enter the location where you wish to delete element:";
        cin>>position;

        if ( position >= n+1 )
            cout<<"Deletion not possible!";
        else
        {
            for ( c = position - 1 ; c < n - 1 ; c++ )
                array[c] = array[c+1];

            cout<<"New set of Elements:\n";

            for( c = 0 ; c < n - 1 ; c++ )
                cout<<" "<<array[c]<<" ";

        }
        cout<< "\nTry another?[y/n]:";
        cin>>ch;
        if(ch=='y'||ch=='Y')
        {
            loopAgain = ture;  // set the flag to loop again
            clrscr();
        }
        else
        {
            loopAgain = false;  // set the flag to stop the loop
    } while (loopAgian)  // while condition instead of goto

    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

What happenes if you use an array instead of a vector?

Jsplinter commented: A simple, but good suggestion. Thank you! +0
NathanOliver 429 Veteran Poster Featured Poster

Using this approach if you use a loop to go back and ask the user for a number if they dont make sure you clear the error flags from cin. Otherwise the flags will stay set and you will always get the error message saying you didn't enter a number even though you did. I would like to add that there are better ways to go about doing this. Here is a little sinpet that will do a little error checking but there are better ways.

#include <sstream>
#include <iostream>
#inlcude <string>

using namespace std;  // just for the example

int main()
{
    float number;
    stringstream ss;
    string input;

    bool goodInput = false;

    while (!goodInput)
    {
        cout << "Please enter a decimal number: ";
        getline(cin, input);
        ss << input;  // puts input into the stringstream
        ss >> number;
        if(!ss.eof())  // was all we got an number?
            cout << "Please enter a decimal number!\n";
        else
            goodInput = true;
    }
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

To test for valid input you generally want to take the input in as a string and check to see if it satisfies the conditions for the type of input you want. If it does than you convert it to the type you want. So if you want to see if the user entered a valid float than you would make sure that it follows the syntax for a float.

Can it have an “-“? Yes, Only one though. Where? Only at the beginning.
Can it have an “.”? Yes, Only one though. Where? As long as there is only one and it comes after a “-“ if there is one.

These are the kinds of steps you have to take to validate string input. I could go on but I would like to see what you can come up with. BTW you can use c-style string or you can use the string type from the STL for this

NathanOliver 429 Veteran Poster Featured Poster

Why does everyone skip the Read this Before Posting sticky before they post thier first post?

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

If you want to know about scanf() check this out. http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

NathanOliver 429 Veteran Poster Featured Poster

If you want to get functions from the user to pass to the program than you might be able to do the following. No guarantee though I am just guessing from the code that you have provided.

string input;
cout << "Enter Equation: ";
getline(cin, input);
Symbolic y(input.c_str());
NathanOliver 429 Veteran Poster Featured Poster

The expression of a switch statement must be of an integer type. That means you can use a single char but not a char array.

NathanOliver 429 Veteran Poster Featured Poster

@ usdblades - When you use a function do you include the data type of the pramater when you pass the variable?

NathanOliver 429 Veteran Poster Featured Poster

If you want to know the size of a vector you would use items.size();. If you want to know the max amount of elements that you can have in the vector before it is resized than you would use items.capacity();.

NathanOliver 429 Veteran Poster Featured Poster

What kind of project are you using? Is it a standard win32 console app or are you using something differently?

NathanOliver 429 Veteran Poster Featured Poster

For a case like this you could use something like this to make sure that you are geting the input you want

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::stringstream ss;
    std::string input;
    int number;

    std::cout << "Please enter a number less than 45 digits: ";
    std::cin >> input;
    std::cin.ignore();  // clear buffer so we can pause at the end
    if(input.size() < 45)  // check if the size is greater than 45
    {
        ss << input;  // input string into the stringstream
        ss >> number;  // output the contents of the stringstream into the interger
    }
    else
        std::cout << "You entered a number that is to large.";
    std::cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

If you want an unsigned 64 bit integer you can use unsigned long long foo;. Check this out to see the data types and their ranges. http://msdn.microsoft.com/en-us/library/s3f49ktz%28v=vs.80%29.aspx

NathanOliver 429 Veteran Poster Featured Poster

You can do that but I would ask why you want to do that. ZWhat are you trying to accomplish with this? A char is basically a 1 byte unsigned integer so if you use 'a' than it gets interperted to 97.

NathanOliver 429 Veteran Poster Featured Poster

I thought what I said was pretty straight forward.

NathanOliver 429 Veteran Poster Featured Poster

So what do you have so far? We dont give out answers here we help oy uget the answer.

NathanOliver 429 Veteran Poster Featured Poster

To display the contents of an array you need to use a loop.

NathanOliver 429 Veteran Poster Featured Poster

If you are only setting the valuse of the array to one or zero based on if they are higher or lower than the average than you can just do that. You dont to use an array of all ones or zeros to do that.

NathanOliver 429 Veteran Poster Featured Poster

Lines 12-15 need to come after line 18. Otherwise you are doing calculations with variables that havent been set yet.

NathanOliver 429 Veteran Poster Featured Poster

The pbroblem is that you are passing the arrays to the function wrong. If you want to pass the arrays it will look like this

cout << distance(x, y) << endl;

Since your function is set up to take an array you just pass the entier array by using the name. what you are doinW is passing the value one past the end of the array

NathanOliver 429 Veteran Poster Featured Poster

One thing to point out is that I don't see the <string> header being included nor do is see std:: preceding string since you are not using a using statement.

NathanOliver 429 Veteran Poster Featured Poster

If you want to ouput the answer as a fraction you either need to code it that way or make some sort of rational number class

NathanOliver 429 Veteran Poster Featured Poster

You might want to check and see if you are even opening the file. to do that you can use this

if(in.fail())
    cout << "The file could not be open;"

I would put that right after line 6 to make sure the file is open before you try to read from it.

NathanOliver 429 Veteran Poster Featured Poster

Line 26 is not correct. When you define a function outside the class boady you would do it like this.

returnType ClassName::FunctionName(paramaters)
{
    // function boady here
}

So in your case it would look like this.

int sample::term()
{
    return ((2 * b) - (4 * a * c));
}

I left out the creation of the local variable because in this case it is not needed. You can simply return the calculation directly.

NathanOliver 429 Veteran Poster Featured Poster

Sounds like you need to redesign how you are getting yourt words from the file and how you are comparing them. Have you ever used the string object?

NathanOliver 429 Veteran Poster Featured Poster

That is not true. Check out the code on this wiki page to see how they use virtual functions with only a pointer to the base class. http://en.wikipedia.org/wiki/Virtual_function#C.2B.2B

NathanOliver 429 Veteran Poster Featured Poster

@prglili5994 - If you are having a problem with the code that you have start a new thread and post your code, a description of what it should do, a description of what it is doing, any error messages you are receiving.

NathanOliver 429 Veteran Poster Featured Poster

Tinnin the code you posted actually works? As far as I know with how c++ works line 11 should be an error. You shouldnt be able to create any array on the stack without knowing the size at compile time. What compiler are you using?

NathanOliver 429 Veteran Poster Featured Poster

Check this out if you are using windows. http://msdn.microsoft.com/en-us/library/windows/desktop/ff468802(v=vs.85).aspx

NathanOliver 429 Veteran Poster Featured Poster

Can you post the code that you have now?

NathanOliver 429 Veteran Poster Featured Poster

According to This Link you can use c++

NathanOliver 429 Veteran Poster Featured Poster

Did you add the icc.c file to the project? This is a header and c file library so you need to include the c file in the project.

NathanOliver 429 Veteran Poster Featured Poster

That’s not really true. A reference is basically a pointer that the complier takes care of dereferencing for you. References also have limitations as that once they are referenced to and object they will always point to that object. Pointers can be change to point at different things at any time. When I code the only time I deal with actual pointers is when I am dealing with arrays. Otherwise I use references for function parameters if i need to be able to modify the variable. If I don’t need to modify the variable and it is a POD (plain old data) type then I will pass by value. If I am dealing with a non-POD type and I don’t need to modify the variable I will pass it by constant reference.

NathanOliver 429 Veteran Poster Featured Poster

What do you mean you need an selection structure? Are you talking about a switch statement?

NathanOliver 429 Veteran Poster Featured Poster

Imagine you have a vector full of pointers to a Polygon type. Now there are many types of polygons and they all derive themselves from Polygon. Some of those derived classes are then turned into base classes for other classes. With virtualization you don’t have to worry about the number of levels there is. You can call "display()" and you can be sure you will get the correct "display()" called.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

If all you are using is the exe file you should be okay. You will still have the issue that the code was compiled for a particular implementation like windows running on an x86 chip. There could also be subtle bugs in your code that don’t show up on your system but will cause issues on other systems. To me portability is more about the code itself than the executable you produce. IMHO portable code should be code that will compile without issue on any standard compliant compiler.

NathanOliver 429 Veteran Poster Featured Poster

I leave that part up to you. You can use the code I provided and change it to do what you want and if you still are having problems then post what you have and ill try to help you out.

NathanOliver 429 Veteran Poster Featured Poster

Something like thisd might help you out

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

using namespace std;

int main()
{
    fstream fin("textfile.txt");
    string userInput, fileLine, response,temp;
    cout << ": ";
    getline(cin, userInput);
    // read lines from file
    while (getline(fin, fileLine))
    {
        //if you find and i
        if(fileLine[0] == 'i')
        {
            // then search for a line begining with r
            while (getline(fin, fileLine))
            {
                if(fileLine[0] == 'r')
                {
                    response = fileLine;
                    break;
                }
            }
            // no guaranty there is a response
            if (!response.empty())
            {
                cout << response;
                break;
            }
            else
            {
                cout << "no match";
                break;
            }
        }
    }
    cin.get();
    return 0;
}

BTW anyone know how to format code in the correctly now? The code button doesnt highlight anything and I havent figured it out yet. The help on formatting the code doesnt help either.

NathanOliver 429 Veteran Poster Featured Poster

Could you post your alien class?

NathanOliver 429 Veteran Poster Featured Poster

The previous line from where? The previous line that matched from the file? Where are you getting the first letter from? Are you getting it from the user input or from the line you got from the file? Please elaborate a little more with what needs to be done.

NathanOliver 429 Veteran Poster Featured Poster

Right off the bat from your code you need to put int GetanInt(); before your main function so that the compiler knows there is a function called GetanInt() somewhere. Secondly you have a semi colon after your function name on line 17. There could be more but thats right from the start.

NathanOliver 429 Veteran Poster Featured Poster

Do you really need 1000000000 bits in one container? What exactly are you trying to do? The problem with bits is that they can’t be stored singularly. The smallest type is char/bool which is one byte. You could do operations to concatenate the bits into some data type and then write that to the file to save space but it can get very complicated.

NathanOliver 429 Veteran Poster Featured Poster

a char* is considered a c-style string. It is just an array of characters. A char ** is and array of char* which is to say it is an group of c-style strings. The string type is an ogject created from the class string. These are two different things. This is a good page for learning about char arrays http://www.cplusplus.com/doc/tutorial/ntcs/
this is a goo page to learn about the string class http://www.cplusplus.com/reference/string/string/

NathanOliver 429 Veteran Poster Featured Poster

according to this http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html
You ahould be able to output direclty to your filestream using the << operator. They also have the >> operator set to get a bitset from the stream.

NathanOliver 429 Veteran Poster Featured Poster

• If all of the elements are in order and the entire array is full wouldn’t you just look at the index of id number - 101?

NathanOliver 429 Veteran Poster Featured Poster

Just make the void RepMatrix funtion a provate function of the class. That way no one can use except you.

NathanOliver 429 Veteran Poster Featured Poster

according to http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx the HANDLE type is a void *. If that is the case than in your copy constructor you should creat a new HANDLE and than asign the value of the copy from HANDLE to the copy to HANDLE. I cant be certian as I havent done any windows api programing though.