NathanOliver 429 Veteran Poster Featured Poster

Im surprised I havent seen him yet.

NathanOliver 429 Veteran Poster Featured Poster

What is the output that you are getting?

Im pretty sure Walt would tell you this but you should use meaningful titles for your threads. Asking for a specific person to check out your code doesnt really say anything about what is going on.

NathanOliver 429 Veteran Poster Featured Poster

you can also use division and the mod operator to do this. if you want to find out how may 10's you can get out of 87 it would look like this.

int amount = 87;
int tens = amount / 10;  // 87 / 10 = 8
amount = amount % 10;  // 87 % 10 = 7
// now amount holds the reaminder which is 7.
NathanOliver 429 Veteran Poster Featured Poster

I think he is using the index of the row as the course number. It kind of looks that way from the way they ask for the course number but it should definitely be spelled out if that is what they are doing.

NathanOliver 429 Veteran Poster Featured Poster

Have you steped through your code to see where it is crashing? Have you put in any cout staements to see what values are before you use them?

NathanOliver 429 Veteran Poster Featured Poster

Lines 112 and 116 are using the comparision equal == not the set equal = operator. Your compiler should be warning you about that. If it is not either use the -wall flag or set you compiler to treat warning as errors.

NathanOliver 429 Veteran Poster Featured Poster

Your arrays are not big enough. They should at least have a size of 10.

NathanOliver 429 Veteran Poster Featured Poster

@np complete - I am running to the sqaure root by doing i * i < number.

@nmaillet - You are correct it should be i * i <= number. Thanks for pointing that out.

NathanOliver 429 Veteran Poster Featured Poster

you need another char array and after strcat( sn, ".txt") you would do strcat( filenameWithFolder, sn)

NathanOliver 429 Veteran Poster Featured Poster

you need to modify your cylinder class to take in the radius and than pass that to the circle class that makes up the cylinder class.

Cylinder::Cylinder(int h, int r) : Circle(r)
{
    height = h;
}
NathanOliver 429 Veteran Poster Featured Poster

Well a prime number can only be divided by 1 and itself. With that you can write a function that you pass the number to check and return a bool for the resault. To find out if a number is prime you need to use the mod operator on it by all numbers up to the square root of the number your checking

bool isPrime(int number)
// add check for number == 1 or number == 2
// add check to see if number is even
for i = 3 to i * i < number // start at 3 since 1 and 2 are prime
    if (number % i == 0) // if there is no remainder than it is not prime
        return false
return true // if we get here it is prime
NathanOliver 429 Veteran Poster Featured Poster

Can you post the code you have now?

NathanOliver 429 Veteran Poster Featured Poster

I wont even read code that is not in code tags.

NathanOliver 429 Veteran Poster Featured Poster

@ Melou22 - Please start a new thread if you have a question. You will also want to show the code you have so far. We dont give out the answers for homework problems but we can help you get the solution.

NathanOliver 429 Veteran Poster Featured Poster

You dont have to put the entire file path if the file lives in the same folder as the .exe file. Only if it is somewhere else than you need to.

NathanOliver 429 Veteran Poster Featured Poster

Thanks deceptokon. I new it was bad but I wasnt sure if the standard said it was illegal.

NathanOliver 429 Veteran Poster Featured Poster

You are still calling main in your if statements to get back to the top of your code. This should NEVER be done. Main is to be called by the OS not the program. You need to rethink your approach so you dont have to call main to get back to entering the birthdate.

NathanOliver 429 Veteran Poster Featured Poster

your arrays that you are making are to large. If you are on a system that has a 8 byte double than each array is going to need approx 75GB of data. To caluculate this you take the rows x colums x size of data type. That gives you 100000 x 100000 = 10,000,000,000 x 8 bytes = 80,000,000,000 bytes. If you change the size to 10,000 x 10,000 than each array would only be approx 800MB. As a side note for large arrays I would suggest creating them dynamiclly at run time so you can use the free store instead of the stack. You can do that like this

//...
const int MAX = 10000;

double ** A, B, C;

A = new double *[MAX];
B = new double *[MAX];
C = new double *[MAX];

for (i = 0; i < MAX; i++)
{
    A[i] = new double[MAX];
    B[i] = new double[MAX];
    C[i] = new double[MAX];
}
//...
NathanOliver 429 Veteran Poster Featured Poster

change B and C inheritance to public and protected respectively

This means that B needs to have public inheritance and C needs to have protected inheritance. They still inherate from the same object just the type of inheritance changes

NathanOliver 429 Veteran Poster Featured Poster

you would change line 32 to

class C : protected A
NathanOliver 429 Veteran Poster Featured Poster

You will want to use an array and a while loop to take in the input. to get the sum you would go through the array with a for loop and add all of the values.

NathanOliver 429 Veteran Poster Featured Poster

Look up the modulus operator. Using that will help you out.

NathanOliver 429 Veteran Poster Featured Poster

I am not seeing an #endif at the end of your Account.h file

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

Here is some pseduo code that might help

int counter = 0
original[] // array you get from user
nodup[] // array without duplicates.
char ch
nodup[0] = original[0]
loop i = 0 until size of original - 1
{
    ch = original[i]
    loop j = i + 1 until size of original - 1
    {
        if ch != original[j]
            nodup[++counter] = original[j]
    }
}
NathanOliver 429 Veteran Poster Featured Poster

to have it keep reading you need to put the code inside of a loop. something like this

//...
char ch;

while(cin.get(ch)) // loop until all input is processed
{
    if(ch == '0')
    {
        for (int index = 0; index < PatternSize; index++) 
        {
            OperandArray bitArray[index] = '0';
        }
    }
    else 
    {
        for (int index = 0; index < PatternSize; index++)
        {
            OperandArray bitArray[index] = '1';
        }
    }
}
//...
NathanOliver 429 Veteran Poster Featured Poster

for a single char you want to use

//...
char ch;
cin.get(ch);

if (ch == '0')
    //...
//...
NathanOliver 429 Veteran Poster Featured Poster

cin.get returns an istream reference not an int. if you want to get an single character than you would do

char ch;
cin.get(ch);
// now ch has 1 letter from the input stream
NathanOliver 429 Veteran Poster Featured Poster

You probolly can get away with changing line 24 to

&b = pb;
NathanOliver 429 Veteran Poster Featured Poster

@ deceptikon. Thanks for that. I had a total brain fart this mornging. Glad you were around to set me straight.

NathanOliver 429 Veteran Poster Featured Poster

line 22 tels the compiler to initialize an empty array. Line 28 does not make any sense to me. If you want to increase the element that you find you would use the post increment operator not the pre increment operator.

NathanOliver 429 Veteran Poster Featured Poster

@ rajat.sethi93 Void main is not standard. Please indent your code. You might want to get a compiler from this decade or at least something that is c++98 standard compliant. There are a number of free compilers/IDE's available. MSVC 2010 express and Code::blocks are a couple to check out.

NathanOliver 429 Veteran Poster Featured Poster

What code do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

Line 17 needs to be inside your if statement in your for loop. The way you have it now it will only add the last factor that you find.

NathanOliver 429 Veteran Poster Featured Poster

If you want it to keep going then you would need to put lines 7 through 35 inside a loop.

NathanOliver 429 Veteran Poster Featured Poster

We wouldnt know where to start. Did you try printing out the values before you divide to see where you are dividing by 0 like WlatP suggested? Learning how to debug your code is an important part of becoming a programer.

NathanOliver 429 Veteran Poster Featured Poster

And what seems to be the problem? It is asking a lot to give us 600 lines of code and not say what problem you are having with it.

NathanOliver 429 Veteran Poster Featured Poster

@mike_2000_17 my c++ instructor that I had last semester wanted use to put struct in front every time we used one. I think the guy never even looked at the c++98 standard.

NathanOliver 429 Veteran Poster Featured Poster

Well if you struct is called Student_info then you would use

typedef std::vector<Student_info> container_Student_info;

The syntax for this is

typedef std::vector<type_of_object_you_want_for_the_vector> name
NathanOliver 429 Veteran Poster Featured Poster

Well to fix number 1 breaking your code into functions and using loops will eliminate the need to call main. To fix number 2 you should take your input in as a string and validate the data that way. You can take a look at this thread to get some ideas http://www.daniweb.com/software-development/cpp/threads/432195/bit-of-weirdness. As far as 3 goes they didn’t start off bashing your program. They gave you some constructive criticism of your code and totally disregarded it and decided to argue about the things they pointed out.

NathanOliver 429 Veteran Poster Featured Poster

In programing there are a lot of things that aren’t necessary for you to do. There are also a lot of things that you can do but shouldn’t do. The fact that the language or the compiler you are using allows you to do it doesn’t mean you should. The best thing to do is to get into the habit of programing in the standard manner. This includes putting code into functions that is going to be reused like your calculation to determine if it is a leap year or not. Your main function should mainly be an entry point for your program, you definitely shouldn’t be calling it from anywhere in your program. I understand that for small projects this might seem annoying but it gets you into the habit of doing it.

If I was you I would listen to what the people here are telling you instead of arguing saying that since it works it is okay. WaltP and deceptikon have some invaluable advice to give and when they give advice I don’t blindly ignore it. That’s not to say you shouldn’t argue a point if you don’t agree but if you are going to, make sure you have some clear examples and/or references to back you up. Learning to code never stops and it takes time to just master the basics. Well there is my two cents.

NathanOliver 429 Veteran Poster Featured Poster

can you post the code for sampleDirection()?

NathanOliver 429 Veteran Poster Featured Poster

You should be able to get rid of lines 64-77. If you just keep track of the smallest difference like you are already doing inside your second for loop you should be okay.

NathanOliver 429 Veteran Poster Featured Poster

What data type are you using for your string? Is it the string type or a char*? It also looks like your code to insert is not complete. What happenes if you want to insert into the middle of the array? How do you get the values into the the array after the insert point? I would also suggest making your code to resize the array its own function and make it private in your class. than you just have a call to rersize if the array isnt big enough and the code to insert the element.

NathanOliver 429 Veteran Poster Featured Poster

I have not seen a for loop used like for readin a file before. When I read from a file I use a while loop. Try doing something like this and see if it helps.

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

using namespace std;

int main()
{
    string input;
    ifstream fin("myfile.txt");
    int count = 0;

    while (getline(fin, input))  // use getline to control the loop.  once the read
    {                            // fails it will end the loop.
        cout << line << endl;
        count++;
        if (count % 24 == 0)
            cin.get();  // used to pause
    }

    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Couple things to point out. First void main() is NOT standard. main should ony return an int. Second your program is using depreciated headers. If you have an older compiler that does not support the new standard header I would suggest you get a new one. MSVC2010 express and Code::Blocks are both free modern compilers. Third you have no indentation. Proper indentation is key for good programing.

NathanOliver 429 Veteran Poster Featured Poster

Well you never initialize k before you use it as your array subscript. you never want to use a variable before you initialize it. void main() is NOT standard. You have two mains in your program. You should use loops instead of goto statements. Your indentation could be cleaned up but thats more of a style thing. You might want to pick better variable names. I could go on but I'll leve it here for now.

NathanOliver 429 Veteran Poster Featured Poster

Are they the string type from the <string> header? If they are the == operator doesnt ignore case so if you input "pick up the knife" it wont work.

NathanOliver 429 Veteran Poster Featured Poster

What you have right now is a sigle letter. If you want to use a c-style string you need to define wrd like char wrd[80] where 80 is the number of charactures max that it can hold. You can change 80 to be what every you want but you want to make sure it is large enough to fit what you want to put into it. you also want to make sure you have enough room at the end for the null terminator that gets automaiticly instered to the end of the input.

int main()
{
    char word[80];  // this will hold 79 letters
    cout << "Please enter a word: ";
    cin >> word;
}
NathanOliver 429 Veteran Poster Featured Poster

What is the type of the variable Input?