Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

delete main() out of stack.cpp and everything links ok for me. Using VC++ 2008 Express.
Do you have stack.cpp part of our compiler's project ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>detailsPtr head;
That is an uninitialized pointer. Set it like this and everything should work. detailsPtr head = NULL;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Further, when I set the new radius, can it be done in a loop inside that function, rather
>>than calling it individually for 21, 22, 23, 24 etc?
I don't know. You probably should post the exact problem.

Warning: be cautious of doing that because some professors may consider it cheating.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is an example

// create instance and use default constructor
sphere obj; 
// create another instance but specifiy the radius
int radius = 20;
sphere obj1(radius);

// now change the radius
radius = 21;
obj.setradius(radius);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 27, you have to pass the pointer CF5 by reference, you are only passing it by value. I only show the corrections to a few lines. Function resize_long_pointer() will require several other corrections to accommodate the double star (pointer to a pointer)

// line 13:
void resize_long_pointer(long **,long *);
...
// line 27
resize_long_pointer(&CF5,&N_Cell_total); 

// line 36
void resize_long_pointer(long **pointer,long *add_size)

Another option is to change resize_long_pointer() to return a pointer long * resize_long_pointer(long *,long *);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where?

All over the new testiment.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

thank you,
I'll keep that in mind when I update my long term goals.
PS. as I m using guru.com and not happy/ is it OK to adv for a web master or other through postings or only thru the google ads I see?
as a moderator I guess you would know?
ray

Do you mean these boards?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your program is experiencing out-of-bounds errors. The arrays are allocated 17 elements numbered 0-16 and your program is attempting to write to elements 1-17. Element #17 does not exist.

Learn to count the C and C++ way -- with 0 as the base value. Your program is chuck full of buffer overruns and out-of-bound errors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

after using cin call peek() to see if the next character is '\n' or not.

int x;
cin >> x;
if( cin.peek() != '\n')
    cout << "Bad\n";

Or get it as a string and check each character.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Pass the open stream to each function as a parameter.

void func1(ifstream& in)
{

}

void func2(ifstream& in)
{

}

int main()
{
   ifstream in("myfile.txt");
   funct1(in);
   funct2(in);

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

According to those pictures men also have much lower IQ than women :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't work because the first number in scores.txt (76) is greater than MAX_CODE_SIZE (50). Just delete lines 46-50 and you will get this:

The number of students with scores 0 - 24 are: 9
The number of students with scores 25 - 49 are: 2
The number of students with scores 50 - 74 are: 0
The number of students with scores 75 - 99 are: 5
The number of students with scores 100 - 124 are: 1
The number of students with scores 125 - 149 are: 3
The number of students with scores 150 - 174 are: 5
The number of students with scores 175 - 200 are: 51

Press any key to continue . . .

Any reason to use that list array ? It isn't use for anything

while (infile >> value)
	{
		if (value >= 0 && value < 25)
		    range[0]++;
        else if(value > 24 && value < 50)
            range[1]++;
		else if (value > 49 && value < 75)
			range[2]++;
		else if (value > 74 && value < 100)
			range[3]++;
		else if (value > 99 && value < 125)
			range[4]++;
		else if (value > 124 && value < 150)
			range[5]++;
		else if (value > 149 && value < 175)
			range[6]++;
		else 
			range[7]++;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your coding style is terrible. Don't be afraid to use more white space -- it won't slow down the compile time any and won't take up any more room on your hard drive.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 56: That brace is in the wrong place, move it up one line. As coded now only line 55 is part of that loop on line 54.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the formula for calculating the monthly payment

int main(){
    float loanAmt;
    float interestRate;
    int   Months;
    float MonthlyPayment;
    cout << "Enter load amount ...";
    cin >> loanAmt;

    cout << "Enter interest rate (e.g. 6.5) ...";
    cin >> interestRate;

    cout << "Enter number of months ...";
    cin >> Months;
    cin.ignore();

    interestRate /= 1200.0;
    MonthlyPayment = (pow((1.0F + interestRate), Months)) - 1.0F;
    MonthlyPayment = interestRate / MonthlyPayment;
    MonthlyPayment = (interestRate + MonthlyPayment) * loanAmt;
    cout << "Monthly payment is " << MonthlyPayment << "\n";

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 65: That's a do nothing line, so you might as well delete it.

you need 8 ranges so create an int array with 8 elements so that array[0] represents the quantity of numbers within the first range, array[1] is the quantity of numbers in the second range, etc. etc.

int array[8] = {0}
...
...
if( value >= 0 && value <= 24)
    array[0]++;
else if( value > 24 && value < 50)
   array[1]++;
// etc
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>My problem is with kbhit(), is there no way of resetting it, so that I can reuse it?
Yes, extract the character from the keyboard

if( kbdhit() )
   getche(); // or some other function that extracts the key

>>The restrictions though was that I should use "standard" libraries only
There is NOTHING in conio.h that is standard C or C++. And there is no standard way to get one character from the keyboard without <Enter> key too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

At the end of getData() you need to add code to remove the '\n' from the keyboard buffer. Getting numbers (ints, floats, doubles) has the side affect of cin leaving the Enter key '\n' in the keyboard buffer, so the next time a character string needs to be entered cin appears not to do anything. Narue wrote a very good article about how to flush the input stream in this link.

>>Also, how can I prevent input of characters other than numbers in integers, float etc?
You have to accept them as strings and parse the characters to see if there are any non-numeric digits.

Another method is to call cin.peek() to see if there is anything in the keyboard except '\n'.

int x;
    cout << "Enter a number ... ";
    cin >> x;
    if(cin.peek()  != '\n')
        cout << "bad data\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>strcat(screenReturnValue,screenClassName.c_str());

You are attemtping to copy screenClassName into some unallocated memory pointer. screenReturnValue must be allocated before executing this line, and it must be allocated enough memory to hold both screenClassName and "Ptr". To fix it, use the new function to allocate the memory char* screenReturnValue = new char[screenClassName.size() + strlen("Ptr") + 1];

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The most irritating and longest bug to fix was in a MS-DOS 6.X program. I had my own multi-threading kernel and several threads. One thread would set the value of a global integer and another thread would read it. One of the threads (foreground screen) would occationally lock up and would not allow the operator to do anything. It took me about 36 hours straight to figure out that I needed to add some sort of thread synchronization.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Then redefine QUIT as 'q'

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if QUIT is defined like this: #define QUIT 3 Then while( ( choice = MenuChoice() ) != 'QUIT' ) will not work. You have to make two changes
1) QUIT should be defined as '3'
2) The while loop should be changed as shown below

#define QUIT   '3'
<snip>
while( ( choice = MenuChoice() ) != QUIT )

>>But when I put 4 for QUIT
You entered the wrong value -- should be 3 not 4

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how is 'QUIT' defined ? Your compiler should have generated an error on that line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try fgets()

char  menuchoice[2];
printf("please enter:");
fgets(menushoice, sizeof(menuchoice), stdin);
return menuchoice[0];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That should be calling members of the Triangle class which is not dependent on any given instance. So just remove Cool.

//Deciding which equations to use
int Triangle::CalcDecider(int choice1)
{
    switch(choice1)
    {
    case 1:
          Equilateral();
          break;
    case 2:
          Isosceles();
          break;
    case 3:
         Right();
         break;
    case 4:
         Obtuse();
         break;
    case 5:
         Acute();
         break;
    case 6:
         TriangleHelp();
         choice1 = TriangleType();
         break;
    default:
        std:cerr << "Invalid Choice. Try again\n" << endl;
        choice1 = TriangleType();
    }
}

Or, some people might code it like this, which is the same thing as above

//Deciding which equations to use
int Triangle::CalcDecider(int choice1)
{
    switch(choice1)
    {
    case 1:
          this->Equilateral();
          break;
    case 2:
          this->Isosceles();
          break;
    case 3:
         this->Right();
         break;
    case 4:
         this->Obtuse();
         break;
    case 5:
         this->Acute();
         break;
    case 6:
         this->TriangleHelp();
         choice1 = this->TriangleType();
         break;
    default:
        std:cerr << "Invalid Choice. Try again\n" << endl;
        choice1 = this->TriangleType();
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>PrintString(*array);
That is not an array of strings like you originally declared because it only has one asterisk. All that takes is one character array. If you want it to print all the strings then you need it like this: printString(char **array); or this printString( char* array[]);

Sh13 commented: thanks for the help +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't -- console programs do not have resources so its not possible to change an icon that doesn't exist.

CodeBoy101 commented: Very Helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've never heard of that kind of triangle. Are you sure it's a valid form?

You mean you have never heard of a four-sided triangle :twisted:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can write your program with notepad but you can't compile it because notepad is not a compiler. If your school computers don't have a compiler then ask one of the teachers if they will download it for you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. Glad to see that another retired person is here.

If you put those classes into a <vector> then you can use std::sort to sort them. All you have to do is write a set of functions that will be called by sort() to return true or false. You would have one of these functions for each data member you want to sort on.

Here is an example of how to use std::sort with an array of classes. About half way down the page you will find this:

struct SAscendingDateSort
{
     bool operator()(CHistoryItem*& rpStart, CHistoryItem*& rpEnd)
     {
          return rpStart->GetTimestamp() < rpEnd->GetTimestamp();
     }
};

And a little further down

// Sort the items in ascending order
     std::sort(HistoryVector.begin(), HistoryVector.end(), 
               SAscendingDateSort());

HistoryVector is a vector of History classes -- vector<Histor> HistoryVector; You might also be able to do this with templates, but I'm not that great with templates so hopefully someone else can help you with that.

[edit]^^^ Good: I see Vijayan had the same idea that I posted.[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A switch statement is really nothing more than a fancy set of if statements and makes the code easier to follow. The default case is not required but often useful just like the else statement.

int Triangle::CalcDecider(int choice1)
{
   switch(choice1)
   {
          case 1:
               Cool.Equilateral();
               break;
          case 2:
               Cool.Square();
               break;
          default:
                cout << "Huh?\n";
                break;
    }
    //Additional code choices 
}

There are times when if statements are better, such as checking for ranges of numbers if( choice1 >= 1 and choice1 <= 10) That would take 10 cases in a switch statement: case 1: case 2: ... case 10:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That is one reason I like to use inline methods in the header file then they are small enough.

struct List{

	int data;
	List *next;
};   // end of struct

class OrderSet{

public:

    // default constructor
    OrderSet()
    {
    }
    // copy constructor
    OrderSet(OrderSet &data)
    {

    }
    // de-constructor
    ~OrderSet()   
   {
   }

	// Member functions

	OrderSet union1();
	OrderSet intersection();
	OrderSet find();
	OrderSet add();
	OrderSet test();
	OrderSet getADTA();
	OrderSet getADTB();
	OrderSet showADTA();
	OrderSet showADTB();
	void mainMenu();

private:

	List a;
	List b;

};   // end of class
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

where is the implementation code for that constructor?

BTW: it is almost never ever the fault of the compiler.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

have you seen this or these ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks for using code tags, but the code you posted contains no carriage returns '\n', and that makes it impossible to copy.

Learn to use your compiler's debugger so that you can step through the problem one line at a time and see what it is doing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

2008 is free from here

>>I would look myself, but I'm at work and almost everything is blocked except Daniweb, luckily enough
If this is for your job then they will have to unblock you.

winky commented: Awesome job... as always +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

add these lines at the top of VectorPivot_once. You will find that bot is 0 and top is -1.

if( bot > m || top > m || bot > top)
    {
        cout << "bot: " << bot << " top: " << top << "\n";
        cin.get();
        return;  
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

download VC++ 2008 Express and that problem will be solved. With the 2005 version you also have to download the Windows Platform SDK, which is pretty large. And it is somewhat complicated to set that compiler up so that it will compiler windows programs. Microsoft fixed those problems with 2008.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

take that ios::ate off the end of line 2 that you posted.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how long have you been programming now? Is this your first semester? Look at what I posted and compare it with what you did. Everybody makes mistakes, but you have to learn to recognize the simple errors you make.

>>But the same thing is happening, no multiple lines etc!?
Of course not because you didn't change the *.exe file. The compiler doesn't replace the *.exe file when there are compile or link errors. There's no point running the old program until all errors are currected.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> where would i put ios::ate?
You didn't read my post very carefully did you? Or the link I posted ??? myfile.open ("lover_names.txt". ios::ate);

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The answer is in the open() function -- see the flags for the second argument. If you want all writes to go at the end of the file the second argument should be ios::ate.

Or you could do seekp() first to set the file pointer to end-of-file. But ios::ate is a lot easier.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

depends. If the code uses normal win32 api functions such as CreateFile() to open the com port, then you shouldn't have to change a thing. The device driver will make it transparent to your program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First create a project, copy the three files into the project's directory and add the files to the project. In the Project tab located in the far left panel right-click on the project name, for example Project1 and select Add To Project

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Pls help me in finding hcf and lcm of 2 nos

What the hell does that mean :angry:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> Stack around the variable buf was corrupted
That means the program has trashed the stack somewhere. That's a tough one to find. Check for buffer overruns, writing beyond the end of a buffer or array, using uninitialized pointers, and indexing into non-existant array elements. If you still can't find it then start commenting out blocks of code until the problem disappears. When that happens you have probably found the deamon.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What I mean is to change "..\bin" to "c:\Dev-C++\bin" You have to do that in each of those directory categories shown in the combo box.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Video here

I'm not having a problem with any of the links I posted. They work ok for me.

The changes for Dev-C++ are just directory settings. Go to menu Tools --> Compiler Options. In there change the relative paths to full paths in each of the tabs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you can get to this page scroll down to the bottom of the page and click the Introduction to Visual C++ Video" link.

Regarding Dev-C++. What version of MS-Windows are you using ? It has a vew problems with Vista that you need to correct in the compile options.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lets say you want an array that can hold up to 10 divisors. Then you would declare it like this: In addition to declaring the array the code below will initialize all elements with 0. int divisors[10] = {0}; Each of the elements of the array are numbered 0, 1, 2, 3, ... 9. Note that the first element is numbered 0, and not 1. And the last is numbered 9 instead of 10.

How lets say you want to find all the divisors of the number 100. The first divisor will be stored in divisors[0] the next divisor in divisors[1], etc.

A divisor is one in which 100 divided by some number (called the divisor) does not have a remainder. So 100 % 2 == 0 means that 100 is evenly divisible by 2 because it does not have a remainder. Therefore 2 is a divisor and should be inserted into the array.

You will want to create a simple loop that counts from 1 to 100 and check each value of the loop counter to see if it is a divisor of 100 (in the above example).