mrnutty 761 Senior Poster

But for the object to move diagonally that would require moving along multiple axis making things ultimately move like cubes. This would also mean gravity and other forces would have a cube effect in their direction. So it would be impossible to just use 3 axis as 3 axis only allows the positioning of objects and not the diagonal movement of objects.

Also I read your link and is basically a bunch of formulas.

Wow. I tried so hard not to post.

Ok now listen to my argument :

Imagine you lye on a Cartesian grid, at the origin. OK ?

Now you say that to get at point, (1,1), we need to first move
1 unit in the x axis, then 1 in the Y axis. Correct ?
Thus the "cube effect" ? And that was your reasoning, correct?


Ok, now let me give you my rebuttal. So imagine you are again
located at point (0,0), in a Cartesian coordinate. And your
target is to get to point (1,1).

Now here is the question : Would, you first move right one, and then up one unit thus ending up at point, (1,1)
or would you simply take a diagonal step towards the point(1,1) ? Obviously, a sane person, would move diagonally. And the reason why one would take the diagonal step, is simple; because we can.

Now here is the more important part, Notice that you …

mrnutty 761 Senior Poster

Use ofstream to save a file. Read up a bit on it and tell me if you know
how to open a file for saving.

mrnutty 761 Senior Poster

do you know how to open a file to save it.

mrnutty 761 Senior Poster

whats the errors?

mrnutty 761 Senior Poster

<quote>

for(int i=0;i<nBalls;i++){
	  TexID[i]= myBall[i].loadBitMap(BitMapList[i]);
//	  myBall[i].draw(TexID[i]);
 }

Put that in your main init function, without the myBall.draw();
I assume TexID is an array of ints?


Put this :

glEnable(GL_TEXTURE_2D);

in your init function as well.

Make sure

glTexCoord2f(object.mapcoord[ object.polygon[l_index].a ].u,object.mapcoord[ object.polygon[l_index].a ].v);

are all of type floats.

Remove this code especially :

glDisable(GL_TEXTURE_2D);
glDeleteTextures(1,(GLuint *)&TexID); //why are you deleting it?

tell me how that goes.

mrnutty 761 Senior Poster

have you any ideas on the save part?

Yes.

1) You need to save your game board
2) You need to save stats : wins, losses, draw games.

Then when you load it in, all you have to do is
fill your game board, and your stats variable.

mrnutty 761 Senior Poster

There is also http://www.gamedev.net/community/forums/ which has really a lot of smart developers that has been programming for a while, and also developing games for a while in the industries. Although its not necessarily c++, post in the beginners section, then there is a 99.99% guarantee, that your problem will be solved, specially, if its related to game programming, but not necessarily.

mrnutty 761 Senior Poster

Thanks for the replies,is this because *p1 is derefrenced here so contents can be added?

Yep, just think about it like this, if ptr is a pointer-to-int, then *ptr,
is the value that it points to , so if it points to an address, which
has the value 4, then *ptr == 4 is true.

int a = 4;
int * p = &a;

int t = *p; // same effect  as int t = 4;
mrnutty 761 Senior Poster

Ok, I am done with finals! That feels good. Now can we get on with this?

Else I will post a start up question in the C++ forumn. Maybe something
normal at first, something like prime finder from 1 to 10 million. See
which one runs the fastest? That way anyone could participate.

mrnutty 761 Senior Poster

>>void Save_Game();

This is not how to call a function.

Since your Save_Game takes an 2d array, you need call your function
like this :

Save_Game( gameBoard) ; //where gameBoard is the board of tic-tac-toe
mrnutty 761 Senior Poster

First is the number -10 < n < 10 ? Is it within -10 and 10 but not including 10?

Or can it be any number?

mrnutty 761 Senior Poster

Add these function inside your classes :

void set_hr(int h);//to set hr then validate it.
void set_min(int m);//to set min then validate it.
void set_sec(int s);//to set sec then validate it.

And make sure the input you get is valid. Example you shouldn't have
negative hours as an input.

mrnutty 761 Senior Poster
int a = 1;
int b = 2;
int *p1 = &a;
int *p2 = &b;
int *p3 = *p1 + *p2;
mrnutty 761 Senior Poster

You can use glGentexture to have opengl generate a texture id, but
opengl automatically does this. I don't remember if the first texture
starts with 0 or 1, but after that every time you load a texture, the id of
that texture is n, where n is the number of total texture it loaded at that point.

mrnutty 761 Senior Poster

Done but still no luck :(
I can't see what the problem is at all....its as if it is only being stored temporarily in memory

Did you call glBindTexture before texturing it. And make sure your
tex coord is correct.

mrnutty 761 Senior Poster

In the meanwhile I've solved it. I needed to use the new-keyword when creating the equipments.

But thanks anyway.

Make sure you match a delete with that!

mrnutty 761 Senior Poster

It works if you do it right :

#include<iostream>
#include<ctime>

using namespace std;

class Random{
private: const unsigned int MAX;
public:
	Random(const unsigned int maxLimit) : MAX(maxLimit) {}
	int getRandom(){
		return rand() % MAX;
	}
};

int main(){
	srand(time(0));
	Random myRand(100);

	for(int i = 0; i < 25; i++){
		if(i && i % 5 == 0 ) cout << endl;
		cout.width(3);
		cout << myRand.getRandom() << " ";
	}
	cout<<endl;
	return 0;
}
mrnutty 761 Senior Poster

>>CEquipment* equipment = &(random_from<CEquipment>(equipments));

This is what you are doing :

int * pointer = 0; //declared somewhere
void foo(){
  int a = 3;
   pointer= &a; //what you are doing
}//end of the brackets

now at the end of the brackets, a gets destroyed, and what does
pointer points too?

mrnutty 761 Senior Poster

Since the size of the file is unknown you need to use vectors to store the
data. I also suggest you to read in the file into a string , from start untill
you reach the ',' comma character. Therefore you will need to use a
vectors of strings.

std::vectors<std::string> contents;

Then you read until the comma character is reached :

std::string tmp;
getline(readFile,tmp,','); //read until the comma character is reached

Of course you will need to read the file until it ends so you need to while
loop it.

while( readFile.good() ){
  std::string temp;
  getline(readFile,temp,',');
  content.push_back( temp ); //add it to our list
   
}

So by now we have all of the content in the file stored inside our vectors
of string. Now all that is needed is to sort the vector. Maybe instead
of using the std::sort method, you should research on the art of sorting.
It will be a good learning experience. The after you have a sorting
code working, all you have to do is to make sure that you are
sorting the vector with respect to the length of its content.

mrnutty 761 Senior Poster

That doesn't seem to work. In fact when I do what you suggested no textures are applied at all :s

Did you enable texture inside the init function. Also remove any
disable call to GL_TEXTURE_2D.

mrnutty 761 Senior Poster

Hi everyone,
Am just a beginner in c++ and have wishes to become good in it..it doesn't mean i should become a expert but just a good programmer. also i have enrolled for a competition in the college which am studying which requires an application to be developed using cpp..can anyone help me in giving topics for the application..applications can be in any field..though am a beginner i got a friend who is intermediate in cpp so even a high end application wouldn't be so difficult..

Read from the top down.

mrnutty 761 Senior Poster

Usually, starters start up using regular arrays, because it easy, plus
usually you don't need to worry about efficiency, and or resizing the array.

But once, you get the idea about arrays, you might want to move up with vectors, and understand how to use them. They are just like
arrays, but you don't have to worry about its complications. All you
need to know is how to use the interface it provides. The other
difference is the initialization part.

>> My question is could I just ask the user for size, store the into a variable, then declare the size of an array using that variable

Yes, you have to use pointers :

unsigned int SIZE = 0;
int *Array = new int[SIZE];
//use it like regular arrays
A[0] = 1;
A[1] = 3;

//after done with using the Array, you need to delete the array
delete [] Array;
mrnutty 761 Senior Poster

In your main class, load in all of the textures in your init function.
Then when displaying the objects, use glBindTexture(GL_TEXTURE_2D,id);
where the id is the id of a certain texture.

mrnutty 761 Senior Poster

My perception of you. serra01 is a spammer.

mrnutty 761 Senior Poster

1) you don't use code tags.
2) You tell me.

mrnutty 761 Senior Poster

Listen to the error : "no matching function for call to `toupper(std::string&)' "

It tells you that there is no function that matches the prototype :
toupper(std::string&). There is however, toupper(char ch);

You will need to make a toupper(std::string&) function , using toupper(char ch).

maybe something like this :

void toUpper(std::string& str){
for i = 0  and i < str.size() , i++){
   str at i = toupper(str at i );
   }
}
mrnutty 761 Senior Poster

start with this :

>>You will add three functions which are:
void set_hr(int h);//to set hr then validate it.
void set_min(int m);//to set min then validate it.
void set_sec(int s);//to set sec then validate it.

mrnutty 761 Senior Poster

Your algorithm is incorrect. When you read in a string, you need to check
the whole array if the string exist. I suggest you use a map, to store the
the value as a key, then you won't have to much work since the map
automatically does not add elements with the same key. What do you think?

mrnutty 761 Senior Poster

First make a palindrome that is case and punctuation sensitive :

You code revised a little :

#include <string.h>

bool palindrome (const char *s)
{
	int index = 0, length = 0;
	length = strlen (s);
        int halfLen = length/2;
	for (index = 0 ;  index  < halfLen;  i++){
		If (s[index] != s[length- index-1]) 
                   return false;
	}
	return true;
}

Now you need to first add a couple of things to it.
1) Makes the sentence all lower or all upper case
2) Deletes punctuation from the string
3) and add other restriction.

mrnutty 761 Senior Poster

It should be :

int count = 0;
for (count = 0; count <= 10 ; count ++)
{
    cout <<"\n\n\n\n";
    cout <<"Please enter player name, or Q to quit";
    cin >> Name;
    if(Name == QUIT) break; //exit the loop
  else{
          //call function to put name in array
	Array_names[count] = format_name(Name); 
     }
}
mrnutty 761 Senior Poster

get rid of all the unneeded " //----// " it makes the code unreadable.

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<cctype>
#include<string>
using namespace std;

 

int main()
{
	//Filestream Object Declaration
	ofstream alphabet( "C:\\alphabet.txt" ) ;
	//Variable Declarations
	string sentence ;
	//User Input Prompt
	cout << "Please type a compilation of alphabet characters in no particular format below, press 'Enter' to count alphabet characters.\n" << endl;
	//Capture User Input Store In string 'sentence'
	getline( cin, sentence );
	//Error occurrence of file write to user
	if( ! alphabet )
	{
		cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
		return -1 ; // Error signal occurrence
	}
	//Successful occurrence of file write to user
	else
	{
		cout << endl;
		cout << "Character compilation saved successfully to 'C:\\alphabet.txt'!" << endl ;

	}
// Write User Input To File 'C:\\alphabet.txt'
	alphabet << sentence << endl;
	// Close Filestream
	alphabet.close();
	

	//Variable Declarations
	int count[26] = {0} ;
	char c ;
	int nonletter = 0 ;


	//Input Filestream Object
	ifstream readAlphabet( "C:\\alphabet.txt" ) ;

	//Error occurrence of file input to user
	if( ! readAlphabet )
	{
		cout << "Error occurred while attempting to open 'C:\\alphabet.txt'." << endl ;
		return -1 ; // Error signal occurrence
	}

	//Successful occurrence of file input to user
	else
	{
		cout << endl;
		cout << "'C:\\alphabet.txt' successfully input to program!" << endl ;

	}

	//PROCESS THE FILE
	readAlphabet.get(c);

	//WHILE LOOP
	while ( ! readAlphabet.eof() ) 
	{
		c = tolower(c) ; // Make all characters lower case

		if (c >= …
mrnutty 761 Senior Poster

First your insert needs to return something.

mrnutty 761 Senior Poster

Got rid of a lot of your errors :

#include <iostream>    
#include <iomanip>    
#include <string>
#include <cctype>  
using namespace std;

//function prototype goes outside main
string format_name(string Name);

int main()
{
	string Name = "";

	//local constants
	int Average = 0;
	const int MAX = 100;
	int At_Bat = 0;
	int Hit = 0;
	string QUIT = "Q";	


	//local variables	
	string Array_names[MAX] = {""};
	int Array_avg[MAX] = {0};


/***********************************************************/
int count = 0;
for (count = 0; count <= 10 ; count ++)
{
    cout <<"\n\n\n\n";
    cout <<"Please enter player name, or Q to quit";
    cin >> Name;	
    while (Name != QUIT)
    {
          //call function to put name in array
		Array_names[count] = format_name(Name);
          }
}
/*****************************************************************/
for (int i = 0; i < count ; i++)
{
cout << "\n\n\n\n";
cout <<"Please Enter At bats";
cin >> At_Bat;
cout <<"Please Enter total hita";
cin >> Hit;

while (At_Bat >= Hit);
Array_avg[Average] = Hit/At_Bat;
}


}


/**********************************************************************
 *Program Name   : 
 *Author         : 
 *Date           : 
 *Course/Section : CSC 110
 *Program Description:  This function is designed to format a string
 *  to be 12 characters long.  If the string is longer than 12 chars
 *  then the string will be truncated.  If the string is shorter than 
 *  12 characters then it will be padded with spaces at the end.
 *
 *BEGIN - Format Name (input string)
 *   Init pad variable to # of chars the name is too long or too short
 *   IF (input string is too short)
 *      Pad …
mrnutty 761 Senior Poster
void FindMaxMin(int x, int y, int z, int &max, int &min)
{
	//FindMax
    if (x > y && x > z)
    {max = x;}
 
	if (y > x && y > z)
	{max = y;}
 
	else
	{max = z;}
 
 
	//FindMin
    if (x < y && x < z)
    {min = x;}
 
	if (y < x && y < z)
	{min = y;}
 
	else
	{min = z;}
 
}

still wrong.

mrnutty 761 Senior Poster

There is no through getting to him. Just let him be.

mrnutty 761 Senior Poster

>>how did you choose your major?

Took a C++ class, loved it, switched over from accounting to CSE.

>>what if you like everything in a scope?
I use brackets limit the scope.

>>what if you're a geek !!
Be proud of it, although "geek" is hard to define.

>>seriously now .. I'm in the faculty of engineering and I have not decided on my major..

Well what do you like so far (besides girls) ?

>>Things in mind are:
- computer Eng.
- software Eng.
- communication Eng.
- electronic Eng.

Which one pops at you?


>>- The future of the major (in 4 years and up)
Do research, and find out how the job market changes. But seriously,
if you do something you love, and it will be enough to pay bills, then
it shouldn't matter.

>>The need/demand

of what?

>>work load/stress

probably a lot, but I'm still in college.

mrnutty 761 Senior Poster
float FindMaxMin(int x, int y, int z, float &max, float &min)
{
	//FindMax
    if (x > y && x > z)
    {return x;}
 
	if (y > x && y > z)
	{return y;}
 
	else
	{return z;}
 
 
	//FindMin
    if (x < y && x < z)
    {return x;}
 
	if (y < x && y < z)
	{return y;}
 
	else
	{return z;}
 
}

Its code like this make me wanna pull my hair.

mrnutty 761 Senior Poster

Yes, :

char space = ' ';
for(unsigned int i = 0; i < str.size(); i++){
    if(str[i] == space){ 
           str[i] = '_'
    }
}
mrnutty 761 Senior Poster

Just by looking at your prototype and what you do with the function
call tells me that this :

int OptionMenu(int);

should be pass by reference.

int OptionMenu(int&);

Or checking again you could do this :

menunumber =  OptionMenu(menunumber);
//instead of 
//OptionMenu(menunumber);

Thats because you need to save the value into menunumber, by
either making it pass by reference or making it equal to its return value.

mrnutty 761 Senior Poster

Code Tags :

/*************************************************************************************************

This is a program I'm writing to calculate test grades and weight in certain tests.

**************************************************************************************************/

#include <iostream>
using namespace std;
int OptionMenu(int);
void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count);
int main()
{ float GA_sum;
float GA_ave;
int menunumber=0;
int GA_count=0;
float GA_number=0;

OptionMenu(menunumber);
system("cls");


switch(menunumber)
{
case 1: 
//GradeAve(GA_number,GA_sum,GA_ave,GA_count);
cout<<"I hope this works!"<<endl;
break;

case 2:
cout<<"help!"<<endl;

default:
cout<<"fixed it"<<endl;
}

system("pause");
return 0;

}

int OptionMenu(int menunumber)
{

cout<<"Choose an option:\n\n1.) Compute grade average.\n\n2.) Calculate a specific tests weight in your final grade.\n\n3.) Store a test grade.\n\n4.) Store a homework grade.\n\n5.) Store a lab assignment grade."<<endl;
cin>> menunumber;

return menunumber;
}

void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count)
{
cout<<"How many grades would you like to process?"<<endl;
cin>>GA_count;

for(int i = 0;i<GA_count;i++)
{
cout<<"Enter a grade:"<<endl;
cin>>GA_number;
GA_sum += GA_number;

}

G_ave = GA_sum/GA_count;

return;
}
mrnutty 761 Senior Poster

Compare your code with just this :

//print 'a' through 'z'
for(char ch = 'a' ; ch <= 'z'; ch++){
   cout << ch << endl;
}
mrnutty 761 Senior Poster

Thanks for the help. Is there anyway to make it into a while loop?

Sure but why ?

int cntr = 0;

while(cntr < length )
{
  //do code
  cntr++;
}
mrnutty 761 Senior Poster

You almost have it, what you need to change is :

string found(float myarr[], float item, int length);
{
  //need a for loop not a while
    for(int i=0; i<=(length-1);i++)
    {
          if (myarr[i] > item)
            return "TRUE";
     }
 //will reach here if above does not return true
  return "FALSE";

}

Next time, use code tags.

mrnutty 761 Senior Poster

>>const double PI=2.0 * asin(1.0);

Just Do : const double PI = 3.14159265;

no reason for the call to asin.


>>include a derive class named sphere from the base circle class.

Means :

class Sphere : public Circle {
}

>>class cylinder : public sphere

Make no sense.

mrnutty 761 Senior Poster

Now you need to do this :

The class should provide a constructor that receives an initial balance and uses it to initialize the data member.

This is towards your Account class.

mrnutty 761 Senior Poster

Remove the global variable and use code tags :

//ACCOUNT.h 
#ifndef Account_H
#define Account_H
double credit, debit, balance;

class Account
{
private :
string name, phone_number, address;
char gender;

public:
void setName(string);
void setGender(char);
void setphone_number(string);
void setAddress(string);
void setCredit(double);
void setDebit(double);
void setBalance(double);

string getName();
string setphone_number();
string setAddress();
char getGender();

double getCredit();
double getDebit();
double getBalance();


};
#endif
....................................................

//SAVINGSACCOUNT.h

#include"Account.h"
class SavingsAcount:public Account

{
private:
double interest_rate;
public:
set Interest_rate(double);
double getInterest_rate();
};

----------------------------------------------------

//CHECKINGACCOUNT.h

#include"Account.h"
class ChechingAcount:public Account

{
private:
double Fee_charged;
public:
set fee_charged(double);
double getFee_charged();
};
mrnutty 761 Senior Poster

>>line 44 `main' must return `int'

refers to you having : "void main()";

it should be :

int main(){ 
//code
return 0;
}

This part :

while (Num_Input =! QUIT)

should be :

while (Num_Input != QUIT) //reads not equal to

This :

void array_insert(int, int, int[]);

is not how you call a function.
this is how you call a function :

#include<iostream>
using namespace std;
void callMe(int a){
   cout<<"hello number : "<<a << "\n"; 
  };

int main() { //notice int main!
  callMe(5); //function call
  return 0; //return 0 meaning exit the program successfully 
}

Another thing :

if (count > ARRAY_SIZE) {...}
else if (count < ARRAY_SIZE) {...}

What happens if count equal ARRAY_SIZE ?

Again , wrong way to call a function :

array_insert(int Num, int Count, int Array[]);

correct way :

array_insert( Num, Count, Array);

Fix all of that in all of you code and then return back if you need to.

mrnutty 761 Senior Poster

Hi there, im new to c programming, just wanted to know is it possible to do a simple if else for 1 username login for C programming? thanks.

Sure :

//declare char *password = "hello";
//ask user for the password
//check if( strcmp(userInput,password) == 0 )
         //if so the let him through
//else exit program

and also, what does c2065 undeclared identifier means? how to fix it?

Depends on the compiler, why don't you post your code?

mrnutty 761 Senior Poster

This part :

if (cin.fail()){
      do{
 
           cout<<"Wrong Data Type of Input!";
           cout << "Please Enter the Product ID Again : ";
           cin >> product[i].id;//whats wrong here??
 
          }while(cin.fail());
}

You need to clear the stream if it fails, so :

if (cin.fail()){   
      do{
           cin.clear() ; //clear the stream
           while(cin.get() != '\n'); //clear out the junk

           cout<<"Wrong Data Type of Input!";
           cout << "Please Enter the Product ID Again : ";
           cin >> product[i].id;//whats wrong here??
 
          }while(cin.fail());
}
mrnutty 761 Senior Poster

Pretty cool. Looks something someone will see if they were high of drugs.