NathanOliver 429 Veteran Poster Featured Poster

thank you for that siddhant3s and Ancient Dragon i did not know that.

NathanOliver 429 Veteran Poster Featured Poster

please open your textbook or your help file and look at the types of operators are in c/c++ before you start typing in symbols. % is not percent in c/c++ it is an operator dealing with integer division.

WaltP commented: Please read Ancient dragon's post, 3 HOURS before you. -3
NathanOliver 429 Veteran Poster Featured Poster

if this is line the line with the problem

cout<<"Series "<<series<<" is approximate on "<<counter<<" iterations"<<" Series "<<series<<" is "<< fixed <<setprecision(digits) << pi1;

after " is" im not sure what you are trying to do in "<< fixed <<setprecision(digits) << pi1; is this the problem?

NathanOliver 429 Veteran Poster Featured Poster

i realized that the time required and the file size will be enormous at a length of 16 digits thats why i was asking but i guess there isn't a way to bypass the rules of a computer system is there? i didn't know though if i was going the completely wrong direction or if i was right and its just that this isn't a realistic thing to pull off.

NathanOliver 429 Veteran Poster Featured Poster

just to be clear if you pass an array into a function by value the array in the calling function will be changed after the called function exits?

NathanOliver 429 Veteran Poster Featured Poster

i see where your going but i want to make sure that i have every possible uppercase and lowercase alphanumeric string you can have in the list. also i know that there are also the characters the normal characters on the keyboard and i have them in there because sometimes they are used.

NathanOliver 429 Veteran Poster Featured Poster

Hi have made some code that will generate alphanumeric passwords and output them into a file. Each password size has its own function so i have 16 functions for sizes 1-16. The code works great its just that as you go up one size in the password size it will increases the time it takes to process by a factor of 96. I was wondering if i was going the long way around or its just a lot of possibilities and I'm SOL

void PassList3()
{
	int counter = 0;
	char password[4];
	for (int i = 0; i < 4; i++)  // sets all char in the array to 0 before starting
	{
		password[i] = 0;
	}
	ofstream fout("Password List 3.txt");
	for (int place1 = 32; place1 < 128; place1++)  // using integer assignment to set the character
	{
		password[0] = place1;
		for (int place2 = 32; place2 < 128; place2++)
		{
			password[1] = place2;
			for (int place3 = 32; place3 < 128; place3++)
			{
				password[2] = place3;
				fout << password << "\n";
				cout << password << "\t\t" << counter << "\n";
				counter++;
			}
		}
	}
	fout.close();
	cout << "\nPasswords saved in: Password List 3.txt";
}

any help would be appreciated.

NathanOliver 429 Veteran Poster Featured Poster

in your void viewAllInfo(Person year1[], int size) you are getting a redefintion error delete your decleration of i from this line. int m1, m2, m3, m4, i = 0; to get this int m1, m2, m3, m4; also in my compiler i hade to include the string header file #include<string> to make the cout statements dealing with strings to output

NathanOliver 429 Veteran Poster Featured Poster

your function for geting the sales for each month is messing you up a bit. you are not returning anything so im not sure why your compiler isnt flagging an error. anyway your input function should be returning the whole array so that when you write month_sales = sales_input(month_sales, 12); in your main function month_sales should recive the entier array. then you should be able to pass it to your totaling function.

NathanOliver 429 Veteran Poster Featured Poster

well the first line in the file will tell you how many beds are in the string. if you are allowed to use std::string then i would just do this

int numberOfBeads;
std::string neckless;
ifstream fin("beads.in");
fin >> numberOfBeads;
fin >> neckless;

if you can't use std::string in this assignment then just use a regular char array. hope this helps.

NathanOliver 429 Veteran Poster Featured Poster

Also just for your information on line 21 you have studentType students[20]; you really do not want to do this. what you have done is declared a global variable and as such it can be used in any function in the program and could lead to errors or unexpected behavior. i know there is a thread on daniweb but i don't remember where its at about global variables

NathanOliver 429 Veteran Poster Featured Poster

move line 7 char AssignGrade(char LetterGrade, studentType students[]); to after you declare you studentType struct on lines 13-19

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
 void StuRead(indata, studentType students[]);
  // AssignGrade() function was here
void Highest();
void Print(students[]);
   struct studentType
{
        string fName, lName;
        int Scores;
        int Tests;
        char grade;
};

char AssignGrade(char LetterGrade, studentType students[]); // this will work here.

the reason for this is that when the compiler comes in it sees the studentType variable but it does not know what it is because you haven't declared it yet in the code.

NathanOliver 429 Veteran Poster Featured Poster

well when i run the simulation it displays hex numbers for awhile and then it will show me 2 sets of hex numbers and then ask me to press enter to continue and every time i do it just does it again. not quite sure whats going on yet but ill get back to you tomorrow afternoon/evening with anything that i find.

NathanOliver 429 Veteran Poster Featured Poster

if want the node clear before you get a new one

Head = NULL;
//or
Head = 0;
Node Head = new Node;

this will make sure it is empty

NathanOliver 429 Veteran Poster Featured Poster

well now you have another beast to deal with. the best of luck getting it running.

NathanOliver 429 Veteran Poster Featured Poster

would you mind terribly much if you messaged me with the code attached so i could try something?

NathanOliver 429 Veteran Poster Featured Poster

alright. what is going on here i believe is that begin.sim[sim].field[x][y].rabbits is giving you a pointer of a pointer so to get down to the original pointer try *begin.sim[sim].field[x][y].rabbits i hope that this will work

NathanOliver 429 Veteran Poster Featured Poster

Thank you. okay to make sure you want pointer to hold the rabbit object right?

NathanOliver 429 Veteran Poster Featured Poster

could you please post the declaration of "pointer"

NathanOliver 429 Veteran Poster Featured Poster

well you could do this

ofstream fout("TheOneFile.txt", ios::app);
fout << something;
fout.close();

this way everytime you need to ouput something into the file you open it, store the information, then close the file. this way you can have every file of source code store information into the file without having to worry that another peice of code has access to that file. to be double sure always include this before trying to store to a file

if (!fout)
errorCondition = true;

you really can do anything if the oppening fails i just put this in as an example.

NathanOliver 429 Veteran Poster Featured Poster

If you want the address of the pointer you would want to say

pointer = &begin.sim[sim].field[x][y].rabbits;

that will give you the address of the pointer not the address that the pointer holds. hope thats what you wanted

NathanOliver 429 Veteran Poster Featured Poster

I believe from what we have here the string will be in the file "beads.in". the first line in the file will be the number of beads and the second line will be the string with the r,b,w characters. what it wants you to do is to parse through the string and find the point where when broken in half you will have the most amount of same colored beads in a row at both ends. then output that answer into a file named "beads.out". post some code of what you got if your still having a problem and i will be happy to help if you need some.

NathanOliver 429 Veteran Poster Featured Poster

I would cycle through each letter in the string that was inputed an see if it was repeated then you will be down to at most a number of checks equal to the size of the string.

NathanOliver 429 Veteran Poster Featured Poster

try this

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int htlen=5;
const int ascLEn=256;
const int ecryptCode=10;
void print_usage()
{
	cout<<"Usage"<<endl;
	cout<<"      lab12 -e file1 file2  Encrypt file1 and write cyphertext to file2"<<endl;
	cout<<"      lab12 -d file1 file2  Decrypt file1 and write paintext to file 2"<<endl;
	exit(1);
}
int main(int argc, char* argv[])
{
	if (argc != 4)
		print_usage();
		if (strcmp(argv[1], "-e") !=0&&strcmp(argv[1], "-d")!=0)
			print_usage();
	ifstream inData;
	ofstream outData;
	inData.open(argv[2]);
	outData.open(argv[3]);
	if (inData.fail()||outData.fail())
	{
		cout<<"File open error!"<<endl;
		return 1;
	}
	string s;
	if (strcmp(argv[1], "-e")==0)
	{
		while (!inData.eof())
		{
			getline(inData, s);
			for (int i=0;i<s.length();i++)
				s[i]=char(s[i] + ecryptCode)%ascLEn;
			outData<<s;
                                                cout << s;    // this will display to the screen
			if (!inData.eof())
				outData<<endl;
		}
	}
	else if (strcmp(argv[1], "-d")==0)
	{
		while (!inData.eof())
		{
			getline(inData, s);
				for (int i=0;i<s.length();i++)
					s[i]=char(s[i]+ascLEn-ecryptCode)%ascLEn;
			outData<<s;
                                                cout << s;  //this will display to the screen
			if (!inData.eof())
				outData<<endl;
		}
	}
	else if (argv[1], "-h")
	{
		int line = 0;
            while (!inData.eof())
            {
              if (line++ < 5)
              {
                std::cout << s << std::endl;
              }
			}

	}
	
	inData.close();
	outData.close();
	return 0;
	system("pause");
}

you use cout to display to the screen

NathanOliver 429 Veteran Poster Featured Poster

i just had a thought and i though that i would at least give it one more shoot. if it is truly a no no to test for floats instead of an integer input then so be it. with that out of the way here it is tell me what you think

#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main()
{
	int number;
	string input;;
	cout << "Please enter an integer: ";
	cin >> input;
	int size  = input.size();
	char * temp = new char[size + 1];	// array to copy the string into for conversion
	for (int i = 0; i < size; i++)
	{
		if ((input[i] == 46) && (i < size - 1))	// makes sure that there is information
		{									// after the decimal point. 46 means "." in ascii
			cout << "you did not enter an integer.\n";  
			return 0;	// you can place anything here but this works for this application
		}
		temp[i] = input[i];	// asigns the string to a char for conversion to an int
	}
	number =  atoi(temp);
	cout << "I got " << number << "\n";
	return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

a pointer to what? another A? the 3.26 was just an example that if both members were float and there was a conversion difference of 3.26 that you could multiply and get an equivalent answer. think of converting Celsius and Fahrenheit and they were structs in your program.

NathanOliver 429 Veteran Poster Featured Poster

oops sorry typo &a.A = &c.C * 3.26; i forgot to dereference the pointers before i use the values. also what is the data type for the member variables in the struct.

NathanOliver 429 Veteran Poster Featured Poster

yep you can do that or you can write a conversion function that takes in a C and will return an A. so if an A is 3.26 times a C you could have

A * convertC(C*);

A * convertC(C * c)
{
            A * a = new A;
            a.B = c.C * 3.26;
            return a;
}

this example assumes that the members are some form float but from what i can tell your member variables have no type.

NathanOliver 429 Veteran Poster Featured Poster

I'm sorry but i think you are going to have to make a sort function. i don't see any other way to take in unsorted data and but it into a list in order. you might be able to check and see if the number you are getting is larger or smaller then the last number and then either go up or down the list to you have the right spot. another way might be to have the assignment of a variable parse the list and put the number in where you want it to go. sorry but it is probably not much help.

NathanOliver 429 Veteran Poster Featured Poster

you could recive the numbers as strings then parsing through them find the decimal point then you will know how many digits are before the decimal point and how many are after for each number then its just a matter of displaying them as you want. maybe that will work for you but it is alot of coding and checking.

NathanOliver 429 Veteran Poster Featured Poster

that is because you do not have a function that can convert struct A to struct C. you must supply one to the compiler otherwise it doesn't know what to do

NathanOliver 429 Veteran Poster Featured Poster

have you tried removing the <= from for( int x = 0; x <= pf.platform_width; x++ ) you may be overwriting the bounds because going to the pf.platform_width with it being equal to 15 will actual give you 16 loops try

for( int x = 0; x < pf.platform_width; x++ )
           for( int y = 0; y < pf.platform_heigth; y++ )

if i could also suggest i would use different variables for the two separate for loops or just output right after receiving the variables such as

for( int x = 0; x < pf.platform_width; x++ )
{
           for( int y = 0; y < pf.platform_heigth; y++ )
           {
                       pf.blocks[x][y] = file.get();
                       cout << pf.blocks[x][y];
            }
}
cout << endl;
NathanOliver 429 Veteran Poster Featured Poster

thank you for the info salem. i just didn't know if having precompiled and loaded during startup was faster or slower during runtime but i guess i see your point because when you start the application it will have to pull all that information off the hard drive and then load it into memory. doing it during runtime allows it to just be created in the memory thus bypassing the file I/O time.

NathanOliver 429 Veteran Poster Featured Poster

i realize that i want to have the array to be the same but i just wanted a random starting number in srand() for the first initialization. the file that the array would be stored in would be a .cpp file and i would compile it into the program so upon startup it would be loaded into the memory. sorry if i didn't make that clear. i was just wondering if there was a point where having such a large for loop to populate the array would take longer then having a program write it out once into a file and then compiled into the program.

NathanOliver 429 Veteran Poster Featured Poster

you never really want to define a global variable. if the variable is to travel around you can declare it in you main.cpp file in the int main() function as a pointer and then pass it around to your different functions and classes as a pointer.

void Cpu::Run(GameBoy * gb)

then you will have your gb object in main() and you can have it in Cpu::Run()

NathanOliver 429 Veteran Poster Featured Poster

would a better way for testing if the float exsist be have have the input recived by a float the raounding it up or down to make the comparision but the then i guess that even it the user entered 5 you could still get 5.00000001 and then all will be lost and you will truly have undefined behavior going on. so lets just stick to strings and we can realy tell what the user has entered.

NathanOliver 429 Veteran Poster Featured Poster

i have and it works just fine i was just wondering if this would be a good way to populate an array the you always want to have the same values but would take forever to write it out and and on a machine like mine takes about 10 seconds to process or longer if i need to make the array bigger

NathanOliver 429 Veteran Poster Featured Poster

hi i have a very large array that i want to populate but i don want to run the for loops every time so i thought i would right a program to output text to fill the array and was wondering if this would work.
the array is int array[100][12][31];

#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <time.h>

using namespace std;

#define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))

int main()
{
	int temp, counter;
	srand(time(NULL));
	ofstream fout("MyFile.txt");
	fout << "int array[100][12][31] =" << "\n" << "{";
	for (int i = 0; i < 100; i++)
	{
		for (int j = 0; j < 12; j++)
		{
			for (int k = 0; k < 31; k++)
			{
				if ((counter % 15 == 0) && (counter != 0))
					fout << "\n";					// after 15 numbers go to a new line in the file
				temp = getrandom(1000, 9999);		// used to get a number for the array
				fout << temp << ", ";				// seperate each element with a "," and a space
				counter++;
			}
		}
	}
	fout << "};";									// ends the array with "};"
	fout.close();
	return 0;
}

i know this is kinda rough but i was hoping it would help, im not anywhere near being done with this program and i may need to increase the array by a factor of 100 before the end so im not sure how much time it will take to populate the array every …

NathanOliver 429 Veteran Poster Featured Poster

first you must have points stored in a file before you can get them from a file.

int plot[21][75];
ofstream fout("MyFile.txt");
for (int i = 0; i < 21; i++)
{
	for (int j = 0; j < 75; j++)
	{
		plot[i][j] = (i + j);
		fout << plot[i][j] << "\n";
	}
}

there this will populate the array and output each element to a text file seperated by a newline charecture. now all you need to do is bring them in like this.

ifstream fin("MyFile.txt");
for (i = 0; i < 21; i++)
{
	for (int j = 0; j < 75; j++)
	{
		fin >> plot[i][j];
	}
}

the reason i used a newline charecture in the output is so that when i use a loop to get the data back they are all on a seperate line and the simple fin >> plot[i][j]; will work fine.
im just using generals right now becuase im not exactly sure how you want it to work in your code but just for a test this is what i wrote for a full program so you can see how it works.

#include <iostream>
#include <stdlib.h>
#include <fstream>

using namespace std;

int main()
{
	int plot[21][75];
	ofstream fout("MyFile.txt");
	for (int i = 0; i < 21; i++)
	{
		for (int j = 0; j < 75; j++)
		{
			plot[i][j] = (i + j);
			fout << plot[i][j] << "\n";
		}
	}
	int nplot[21][75];
	ifstream fin("MyFile.txt");
	for (i = 0; …
NathanOliver 429 Veteran Poster Featured Poster

thank you tux4life for your input i i realized the typo after i submitted the reply and as for the conversion to a double in the if() statement i knew that would happen but so far it was a quick and dirty way to test. i guess the best way for testing that i have found is placing the input into a string then converting. or you could use cin.getline(ch,20,"."); to test and see if there is a decimalpoint in the response.

NathanOliver 429 Veteran Poster Featured Poster

Ancient Dragon and jen140 are both correct you have a missedmatched bracket from line 214 that does not necsisalry mean that the bracket on 214 is wrong but there is one before that. make sure you know how your debugger works. FYI it will always flag an error past where the original culprit is at.

NathanOliver 429 Veteran Poster Featured Poster

move your cout << endl to after the loop with the n term

for (int i = 0; i < 6; i++)
{
         for (int n = 0; n < (i+1); n++)
         {
                  cout << n;
          }
          cout << endl;
}
NathanOliver 429 Veteran Poster Featured Poster

here is another solution

double input;
int test;
cout << "Please enter an integer: ";
cin >> input;
test = input;
if (test != input)
{
       cout << you did not enter an integer.";
}

basicaly what you are doing is let the number come in as a double then store it into the int test. if the number is a float then test will be rounded and the resualting if statement will be true and then you will know. hope this helps

tux4life commented: Very nice :) !!! +3
siddhant3s commented: Never compare two floats -1
jephthah commented: this is not a solution, and should not be green. +8
NathanOliver 429 Veteran Poster Featured Poster

im guessing that you are getting an error with trying to store into inches[ct]. you might want to recheck on how to declare an array.

NathanOliver 429 Veteran Poster Featured Poster

one thing i would suggest is that you should make a varible class that holds all the information, then you could store them in a dynamic array inside the polynomial class and sort them by order of the power of x.

class varible
{
public:
 varible(coeff, powerOfX);
~varible() {}
private:
int coeff;
int powerOfX;
};

hope this helps

NathanOliver 429 Veteran Poster Featured Poster

im not sure why you are even returning C in this function becase you already have it defined in the global namespace. anything you do inside the function will automaticly change C to what you are doing. also for your information even though an array is a type of pointer you still will need to derefernce the array to pass it as a pointer