mrnutty 761 Senior Poster

Make your first for loop like so :

for ( i=2;i<=40;i++)

Then make your second for loop like so

for(i2=2; i2<i; i2++)

The main problem is that you are printing inside the loop. Print outside.
You overall loop could look like this :

int i = 0, i2 = 0;
	for(i = 2; i <= 40; i++){
   for(i2=2; i2<i; i2++){
      if(i % i2 == 0 && i != 2) break;
   }
  if(i2 == i)print "i" is prime;
  else print "i" is not a prime;

}

See how the print is outside the second loop.

mrnutty 761 Senior Poster

This is wrong :

void getshape(char shape[MAX_ROW][MAX_COL])
{
     char end='.';
     printf("Enter a shape and when your done enter '.'\n");
     while ((end=getchar()) != '.')
     {
           shape[MAX_ROW][MAX_COL]=getchar();
     }
     return;
}

shape[MAX_ROW][MAX_COL] is invalid memory access.
This is also wrong :

void fillArray(char shape[MAX_ROW][MAX_COL], int row, int column)
{
    if (shape[row][column] == '*' || shape[row][column] == '#') return;
    else
    {
     shape[row][column] = '*';
 
	 fillArray(shape,row+1,column);//down
	 fillArray(shape,row-2,column);//up
	 fillArray(shape,row,column-1);//left
	 fillArray(shape,row,column+2);//right
  }
}

I don't know why you are moving column-2 or column+2. Move only
1 step.

mrnutty 761 Senior Poster

I am stuck with one problem , please anyone help me to do this . The question is

Write a function to modify a list ( one dimensional array ) of numbers such that every number is replaced by the average of its immediate neighbours ( the value just above and just below ). Include appropriate special steps for the first and last elements .

First create a function prototype. You know you need an array,
you also know you need the array size. So create a prototype first.

From high school you know that the average of 2 numbers,a,b is
just (a+b)/2.0f; Use this information to find the average of
the array for each elements. For example the average of Array[3] ( assuming validity ), will be
(Array[3-1] + Array[3] + Array[3+1] ) / 3.0f;

You can do this for all elements in the array, except the first and the last, because there is nothing preceding the
first and there is nothing further than the last. In those case, you have to do something else.

mrnutty 761 Senior Poster

These are wrong :

double calcFwt (double wkPay, double fwt);
       {
               return fwt = 0.20 * wkPay;
       }
 
double calcFica (double wkPay, double fica);
       {
                return fica = 0.08 * wkPay;
       }
 
double calcNetPay (double wkPay, double fwt, double fica, double netPay);
       {
                  return netPay = wkPay - (fica + fwt);
       }

There are at least 2 things wrong with each function. Try to find out that
it is.

mrnutty 761 Senior Poster

This is wrong right of the back, "while (found=false && first<=last)".

This is also wrong :

else if(searchValue>array[midpoint])
    last=midpoint-1;
else 
   first=midpoint+1;

Any clue why?

mrnutty 761 Senior Poster

>> While that is a correct solution

I beg to differ. Thats far from a correct solution.

mrnutty 761 Senior Poster

Because as of right now you have to include the definition of the template class in the same file as the template header. If your compiler supports the
keyword export, then you can separate them.

mrnutty 761 Senior Poster

>> can anyone help me initialize this array with nested for loops?

Do you know how to do it for a single for loop, i.e initialize say an Array[4]
using a for loop?

mrnutty 761 Senior Poster

Or just get it as a string and see what it contains. For example :

string number;
cin >> number; //say user entered "123"
int  a = number[0] - '0'; //a = 1
int b = number[1] = '0'; //a = 2
int c = number[2] = '0'; //a = 3

We subtract '0' because its an char offset, to convert from char to int
decimal.

mrnutty 761 Senior Poster

The inner loop is O(n^2), the most outer loop is log(n) [ I think ],
so I would guess its log(n)*O(n^2).

mrnutty 761 Senior Poster

>> I don't plan on extending my knowledge of C++

Thats too bad. I guess you don't wan't to further your knowledge about
programming.

>>that may come later on if I make another game, since it would make it a whole lot easier to navigate

Ok, I will be waiting for the next game with separated files.

mrnutty 761 Senior Poster

Then go for, Lucas series. The only difference is the starting value.
For fibonacci f(0) = 1, and f(1) = 1. Then its defined recursively as
f(n) = f(n-1) + f(n-2), where n >=2.

For Lucus series, f(0) = 2, and f(1) = 1, then its defined recursively as
f(n) = f(n-1) + f(n-2) , where n >=2.

As you see they are very similar, yet different. So all you need
to do is change your starting values.

For example you can do something like this to generate fibbonicci
numbers

//initial value
	const int F_0 = 0;
	const int F_1 = 1;

	const int UPTO = 20;
	
	int currNum = F_0;
	int nextNum = F_1;

	int result = 0;

	for(int i = 0; i < UPTO; ++i){
		result = currNum + nextNum;
		cout << "fib(" << i <<") = " << result << endl;		
		currNum = nextNum;
		nextNum = result;
	}

Now if you change F_0 = 2 and F_1 = 0, then you generate the lucus number. The main point here is to see that fibonacci numbers
rely not only on their recursive definition but also the initial condition.
You don't have to generate the Lucus numbers, just realize that
by changing the initial value, or the starting value, you generate
your own set of sequence, call it aswin sequence, long as its not already
founded.

mrnutty 761 Senior Poster

Its good. The source is just not so flexible. You should separate it into
files. Make use of structures, if you know how. You use mostly brute force,
even with variables. Also do not use magic numbers, use constants, so
its more readable and clear. Your source has a lot of redundant code. So far its good though. Nice job.

mrnutty 761 Senior Poster

As always, practice makes close to perfect. Type as much as you can
and eventually you will get better.

mrnutty 761 Senior Poster

We're not physics. Post your code!

Its probably something wrong with your program. Maybe the "1" in "104"
is your boolean variable and the 04 is something else.

WaltP commented: It's not "physics", it's "psychics" :o) +9
mrnutty 761 Senior Poster

Oops your right, "numerical", "sequence" and "containing " have leading spaces. Hope mods can fix that. Thanks for pointing that out.

mrnutty 761 Senior Poster

We are all tired of from our daily lives. So I suggest to sit back and
play this game. I present here a hangman game( text version ) for
your enjoyment. There might be some bugs as I haven't throughly
tested it, so sorry if you find it( I'm sure you can fix it ). Happy late
Chinese new year! P.S no cheating, and get your vocabs up...

mrnutty 761 Senior Poster

Your sort array needs another for loop.

mrnutty 761 Senior Poster

You need to realize the conversion between 2d array and 1d array.
Namely, that 1D_Row = 2dRow * MAX_ROW + 2D_Column;
In code it would look like this :

for(int row = 0; row < MAX_ROW; ++row){
  for(int col = 0; col < MAX_COL; ++col){
     Array1D[col + row*MAX_ROW] = Array2d[row][col]
  }
}
mrnutty 761 Senior Poster

This

void setDrawRectangleBorder()
{
	char border;
	cout << "Enter the character you would like to see as the border of the rectangle:";
	cin >> border;
 
}

Does not do anything useful.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

The warnings tells a thousand words :

30 [Warning] ` class Kontrolka' only defines private constructors and has no friends 
33 [Warning] ` class KontrolkaAtomowa' only defines private constructors and has no friends 
36 `Kontrolka' with only non-default constructor in class without a constructor

Realize that in a class, if you don't specify a modifier, the function inside
of a class, the constructors, the destructures, and the member variables
are all private.

For example this class :

class Kontrolka : public NieDesktop{                      //abstract
    Kontrolka(const Kontrolka&);                 
};

The constructure you provided is private, because its that way by default. To solve your problem make the constructure pubilc, for this
one and you other ones.

mrnutty 761 Senior Poster

I really do wan't to help you, but I can't. Your code is hard to read.
I would recommend you to indent your code. Then give it a try and see
what happens. Then maybe shorten it as much as possible to show us
what problem you are having.

mrnutty 761 Senior Poster

Try to make your own using the ctime header. Here is some starter code

class Timer{
private:
  long startTime;
  long endTime;
public:
 Timer() {
   startTime = endTime = clock();
  }
 void startTimer(){
 }
 void stopTimer(){
 }
 long getElapsedMilliSeconds(){
 }
 long getElapsedSeconds(){
   return getElapsedMilliSeconds() * CLOCKS_PER_SEC;
 }
 float getElapsedMinutes(){
  return getElapsedSeconds() / 60.0f;
 }
};

obviously you have to fill in the blank code.

mrnutty 761 Senior Poster

The problem is that D3DXVECTOR3 is not being found for whatever
reason. Have you linked ALL of the lib and headers? Maybe something
got corrupted.

>>I've actually been building this from a tutorial (its beginners DirectX for C++ Veterans) where the source code compiles and runs perfectly, yet, even pasting the source into my project (or even only pasting SMALL parts of it) yields the Unresolved external errors.

This tells me that you are not linking your lib and headers properly.
Why, because when you unzip their project, included are the dlls
for directX and thus the .exe works because it finds them in the same
directory. But you say that you pasted the code and it gives you
a linking error, which definitely means that you did not link the files
correctly.

mrnutty 761 Senior Poster

In recursion there are 2 main things :

1) basis :
2) Induction.

In you recursive, you have provided the Induction, namely
f() = f(), but you have not provided a basis case.

Here is an example of a recursion function. Again, a recursion function
has a basis and the Induction.

//example of recursion
void printXTimes(int printWhat, int howMany){
    if( howMany == 0) return; //our basis...

    cout << printWhat; //print whatever is passed in
    printXTimes(printWhat, howMany-1); //our Induction
}

As you can see we reduce howMany by 1 in ever recursive call.

The above function is a recursive function because it has a basis case
and an Induction. It is defined as follows :

Our function is defined as, F : N --> empty , where empty means it
returns nothing. Then our basis and induction are :

Basis : n = 0
Induction : F(x,n) = F(x,n-1)

MrYrm commented: thx for the info +0
mrnutty 761 Senior Poster

>>if (answer!=df1/df2)

what happens if df2 > df1. For example say df1 = 20 and df2 40

answer = df1 / sf2 = 20 / 40 = 1/2 = 0.5

Thats a fraction. And your variables are of type Int. That means
the real answer gets truncated. Which means if that question comes
up then the correct answer according to your program will be 0,
since int answer = 20/40 ; // which = 0

Did you even try out your program? It fails to get the real answer
for most of your division program.

mrnutty 761 Senior Poster

Use std::copy. If not then create your own like so.

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

template<typename Container>
void print(const Container c){
	Container::const_iterator itr = c.begin();
	cout << "{ ";
	while(itr != c.end()){
		cout << *itr++ << " ";
	}
	cout << "}"<<endl;
}
template<typename SrcIterator,typename DestIterator>
void myCopy(SrcIterator srcBegin, SrcIterator srcEnd, DestIterator dest){
	while(srcBegin != srcEnd){
		*dest++ = *srcBegin++;
	}
}
int main()
{	
	string src = "1234567890";
	std::vector<char> dest;
	
	//using std::copy method
	//copies src into dest, while expanding dest as needed
	copy(src.begin(),src.end(),std::back_insert_iterator<std::vector<char>>(dest));
	cout << "Vector now contains : ";
	print(dest);
	cout << endl;

	
	string src2 = "abcdefghijklmnopqrctuvwxyz";
	std::vector<char> dest2;

	//using myCopy function
	//copying src2 into dest2 while expanding size of dest2 if necessary
	myCopy(src2.begin(),src2.end(),std::back_insert_iterator<std::vector<char>>(dest2));
	cout << "Vector2 now contains : " ;
	print(dest2);
	return 0;
}

I recommend using std::copy so there is no chance for mistake.

mikabark commented: Thanks you so much. +1
mrnutty 761 Senior Poster

>>For more info, check out the tutorial on Narue's website.

Is he the founder?

mrnutty 761 Senior Poster

Use cout and cin instead of the C function printf and scanf, after all this
is C++.

Using rand, you have the correct idea, but you also have to seed it.
Insert this code : srand( time(0) ) at the very beginning of your main.
That code seeds the rand function so that it spits out seemingly random
numbers. You will have to import ctime header file to use time(0);

mrnutty 761 Senior Poster

>>But, I've been told that srand() will produce a better random number

Whomever told that to you should not talk about programming anymore.
All srand does is seed the random number generator.

>>a good one is the mesner twister
>>It's called the Mersenne Twister.

Yes that is better than rand, however usually, rand should suffice for
newbies.

mrnutty 761 Senior Poster

>The use of destructor is to delete or release any memory that has been allocated.

Nope. It is a method which is automatically invoked when the object is destroyed.

Yes I said that here " When the double linked list gets destroyed, its destructor will be called."

mrnutty 761 Senior Poster

>>const char *str1 = "pointer to constant"

That means that the pointer points to a const data. Which means that
the pointer can't change the const data that its pointing since a const
data cant be changed. But it can point to somewhere else.

>>char *const str2 = "constant pointer";

That means the pointer is const and cannot change what its pointing to.
But it can change what its pointing to.

>>const char *const str3 = "constant pointer to constant";
That is a combination of the 2 stated before. It is a const pointer which
points to a const data. That is, it cannot change the value its pointing to
nor can it change the address that its pointing to.

The rest of the code is just showing the above statements.

mrnutty 761 Senior Poster
mrnutty 761 Senior Poster

Inside your fill function, check if row and col is out of bounds.

mrnutty 761 Senior Poster

Cross platform, I would say openGL is your best bet.

mrnutty 761 Senior Poster

>> shape[MAX_ROW][MAX_COL] = '*';

That is wrong. Using MAX_ROW and MAX_COL is wrong. It is 1 passed the
index, and does not contain any valid data. Just leave that code out.

mrnutty 761 Senior Poster

The use of destructor is to delete or release any memory that has been
allocated. In Java, they handle the garbage collection for you. C++
is not as friendly. You have to use the destructor to delete or handle
anything that needs to be handled when the object gets destroyed.
As your double linked list example, you will use new to allocate new
memory. When the double linked list gets destroyed, its destructor
will be called. And in the destructor you will have to write the code
to delete the whole list.

mrnutty 761 Senior Poster

No since the return type is of char reference, that means you can
change the value while accessing it as well.

mrnutty 761 Senior Poster

In C++ easy as 1,2,3 :

double toDouble(string str) //1 -- define function
{
  //2 -- use simple logic and some stream object
   stringstreamm convert; 
   convert << str;
   double val = 0.0;
   convert >> val;
  return val; //3 -- return value, assuming it was a success.
}
mrnutty 761 Senior Poster

>>However, the flamethrower works in a totally differentmanner, ie. calling my particle engine, while my MachineGunClass, simply calls a glPoint.

Yes I also mentioned that here in my previous post, "The point here is that, they do differ internally, but not so much externally".

class WeaponMasterClass
{
virtual Shoot();
virtual Reload();
virtual BulletsLeftInClip();
virtual IsReloading();
// virtual vars I need, ect.
};

>>And then calling this, with it set equal to some other weaponobject, lets say the flamethrower, would make it use the flamethrowers shoot, instead, since it's virtual?

Yes, if the flamethrower object is derived from that base class.
Not exactly, you will need its return type as well.

>>P.S.: Virtual, vs. Pure Virtual

Virtual and not Pure Virtual.

mrnutty 761 Senior Poster

>>[edit]wow...i'm slow....[/edit]

Yep. We are super ninjas.

Nick Evan commented: We are indeed :) +12
mrnutty 761 Senior Poster

>>Anyways you should be able to fix the problem you have by declaring pBeam in a global scope (by declaring it outside of functions at the top of your file).

You should but that is not a good solution. Don't start of learning bad practices. It will only come back to haunt you. I can't look at your code right now, but I might get back at this later.

mrnutty 761 Senior Poster

>> 1)if i wanted to write a line of code needed to declare a 1-dimensional array named names that can hold 8 string values would this be correct?: char names[8];

Nope what you declared is an array of chars. chars are just 1 character. For example 'a' is a char, '1' is a char.

>>how would i write the code needed to assign strings to each element of the array names from question 1) above

Access the element and use the assignment operator. The r and l value will depend on what type is the variable.

>>if i wanted to write the line of code needed to declare a vector named myList that can initially hold 5 integer values would this be correct? vector<int> myList(5);

Yes, you can also do this : std::vector<int> myList(5,0); That sets
all the 5 values initially to 0.

>>how would i write the line of code to assign 18 to the 6th element of the myList vector from question 3) above...that is 1 past the initial number of elements set for myList?

Many ways. One way is to use the pus_back method.

std::vector<int> vec(5,0); // 0 0 0 0 0
vec.push_back(18); // 0 0 0 0 0 18
mrnutty 761 Senior Poster

ok

Make sure that you check if startX and startY is within the boundaries
of the array, and also that its not equal to the wall.

mrnutty 761 Senior Poster

Put that code inside your main, before calling the fillArray function.
Then pass that onto the fill Array function like so :

int main(){
  //....
  cin >> startX >> startY
  fillArray(Array,startX,startY);
  //...
}
mrnutty 761 Senior Poster

this is your problem :

fillArray[r][c] = '*';

that should be

shape[r][c] = '*';
mrnutty 761 Senior Poster

Just make a wrapper function :

void print(std::string msg, int posX, int posY, int color){
 textout_ex(screen, font, msg.c_str(),posX, posY, color);
}

And use it like so :

void doo(){
 string msg = "hello 2d world!";
 print(msg,0,0,makecol(255,0,0));
}

an even better wrapper :

void print(std::string msg, Vec2d pos, int color){
 textout_ex(screen, font, msg.c_str(),pos.x, pos.y, color);
}

Where Vec2D is a class that holds the x and y position of an object.

mrnutty 761 Senior Poster

Change the name from fill to fillArray and see what happens.

mrnutty 761 Senior Poster

>> the flamethrower works differently then the gun

Does it?

The flamethrower shoots and so does the gun.
The flamethrower has some mass and so does the gun
The flamethrower can run empty and so does the gun.

The point here is that, they do differ internally, but not so much
externally. Thus a solution to your problem is to create a hierarchy
with virtual and pure virtual functions, as pointed out already, while
making the have the same functions like shoot() or destroy(), or whatever.