Yellowdog428 17 Light Poster

Here is my code for adding an enemy to the board.

void Level::addEnemies(int num)
{
	int i = num;

	while (i > 0)
	{
		int xpos = int(float(((rand() % width) + 1) - 1));
		int ypos = int(float(((rand() % height) + 1) - 1));
		
		if (level[xpos][ypos] != TILE_WALL)
		{
			Enemy *temp = new Enemy(this, drawArea, SPRITE_ENEMY, (float)xpos, (float)ypos);

			temp->addGoal(player);

			addNPC((sprite *)temp);

			i--;
		}
	}
}
void Level::addNPC(sprite *spr)
{
	npc.push_back(spr);
}

this is getting pushed on the stack which I iterate through.

So the problem is the code works well until I remove, possably the last on the stack? I am guessing that decrement of the last/first on the stack it throws up.

Yellowdog428 17 Light Poster

Well if I remember correctly when delete is called on a pointer to an object the deconstructor is called for that object?

I figured the pointer was still there tho referencing that object so calling the remove on a list with a referance to that object then it would get removed off the stack?

Yellowdog428 17 Light Poster

So I am getting a runtime error and I have narrowed down the problem to this method.

I am still learning about iterators and I assume that the problem is with this part of the code, getting the expression error

list iterator not decrementable.

Any help would be appreciated.

void Level::update()
{
	
	for (Iter = npc.begin(); Iter != npc.end(); Iter++)
	{
			//dereferance *Iter to use pointer notation
			(*Iter)->idleUpdate();

			if ((*Iter)->isAlive() == false)
			{
				sprite *temp = *Iter;

				Iter--;
				delete temp;
				npc.remove(temp);				
		}
	}
}
Yellowdog428 17 Light Poster

Perhaps someone can help me here, I have a method that I am trying to accomplish two things

1. Retrieve a table from a stored procedure passing it one variable
2. Downloading that table in csv format

I am not sure why this method is not working and I am sure it is just a simple syntax error or my logic may be a little funky somewhere so any help would be appreciated.

protected void btn_export_Click(object sender, EventArgs e)
        {
            string filename = this.drpDealers.Text + "_mailfile";

            SqlConnection con = new SqlConnection(connectionString);
            DataTable tblMail = new DataTable();

            SqlCommand cmd = new SqlCommand("web_pull_mail_list", con) { CommandType = CommandType.StoredProcedure };
            cmd.Parameters.AddWithValue("@dealer_id", (Convert.ToInt32(this.drpDealers.Text)));

            cmd.Connection = con;

            con.Open();
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            adapt.Fill(tblMail);
            con.Close();


            HttpContext context = HttpContext.Current;
            context.Response.Clear();

            foreach (DataColumn column in tblMail.Columns)
            {
                context.Response.Write(column.ColumnName + ",");
            }

            context.Response.Write(Environment.NewLine);
            foreach (DataRow row in tblMail.Rows)
            {
                for (int i = 0; i < tblMail.Columns.Count; i++)
                {
                    context.Response.Write(row[i].ToString().Replace("," ,string.Empty) + ",");
                }
                context.Response.Write(Environment.NewLine);
            }

            context.Response.ContentType = "text/csv";
            context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ".csv");
            context.Response.End();
        }

Thanks in advance for any help

Yellowdog428 17 Light Poster

This may seem like a simple question but I for the life of me cannot seem to get this working.

I have an ASP page that I need to set a dropdown box to a value from sql.

I have the dropdown getting filled from sql no problem.

private void fillDMSType()
        {
            this.drpDMSType.Items.Clear();

            string selectDMStype = "select distinct dms_type_alias, dms_type_id from dms_types";

            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectDMStype, con);
            SqlDataReader reader;

            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ListItem newItem = new ListItem();
                    newItem.Text = reader["dms_type_alias"].ToString();
                    newItem.Value = reader["dms_type_id"].ToString();
                    drpDMSType.Items.Add(newItem);
                }
                reader.Close();
            }
            catch (Exception err)
            {
            }
            finally
            {
                con.Close();
            }
        }

The problem is when the page loads I need to set the dropdown to a corresponding request from sql.

protected void getDealersDMSAccessValue(int dealerID)
        {
            SqlConnection con = new SqlConnection(connectionString);
            DataTable tblDMS = new DataTable();

            string dmsInfo = "select * from dms_types where dealer_id = " + dealerID;

            SqlDataAdapter adapt = new SqlDataAdapter(dmsInfo, con);

            adapt.Fill(tblDMS);
            if (tblDMS.Rows.Count > 0)
            {
                //this.drpDMSType.SelectedIndex.Equals(tblDMS.Rows[0]["dms_type_id"]);
                // = (int)tblDMS.Rows[0]["dms_access_method_id"];
                this.dmsdrpid.Text = (string)tblDMS.Rows[0]["dms_type_id"].ToString();
                //this.drpDMSType.SelectedValue = (string)tblDMS.Rows[0]["dms_type_id"].ToString();
                this.drpDMSType.SelectedItem = this.drpDMSType.Items.FindByText((string)tblDMS.Rows[0]["dms_type_alias"]);
            }
        }

I have searched high and low and cannot seem to figure the correct way to do this.

Again I am sure that it is pretty simple and I am just missing something. Any help would be greatly appreciated.

Yellowdog428 17 Light Poster

Hay guys I am looking for some help here

I have a page in asp that I am trying to get a button to display a pop up with the value of a textbox on the parent page.

This should be a simple popup with a multiline textbox inside it that takes the value of a textbox and parses the text into a multiline view with line breaks on a double pipe ||

any help getting this started for me would be great.

The page should not use javascript and can be handled in C# code on the back end if needed.

I wish I had some code to show you all but I am at a loss as to get this started.

Thanks in advance on any help you can all give me on this problem

Yellowdog428 17 Light Poster

I am trying to figure out how to set multiple text boxes/labels with one sql query.

I dont need help connecting to the database or anything like that I just need to know how I can write one query to and set multiple text boxes with that one query.

here is what I have been doing, and there has got to be an easier way.

string selectAddress = "select cust_address from customers where customer_id = " + customerID;
string selectCity = "select customer_city from customer where customer_id = " + customerID;

SqlCommand cmdAddress = new SqlCommand(selectAddress, con);
SqlCommand cmdCity = new SqlCommand(selectCity, con);

this.lblAddress1.Text = cmdAddress.ExecuteScalar().ToString();
this.lblCity.Text = cmdCity.ExecuteScalar().ToString();

I would like to be able to write one query (actually just put it in a procedure) and set the text boxes/labels to the results of the query.

Thanks in advance for any help!
Cheers

Yellowdog428 17 Light Poster

Well its really strange, so the code above works fine from a form application but from a service it does not..... same code differant beast so my next question is...

Does anyone know what would make a piece of code not work from a service that will work in a form application?


Thanks in advance

Yellowdog428 17 Light Poster

I am having a problem running an ssis package from a service written in C#.

Here is my code

try
            {
                //Package Path
                string packagePath = @"C:\\data_from_listcleanup\\programmability\\Package.dtsx";

                //create an instance of the package
                Package goPackage = new Application().LoadPackage(packagePath, null);

                //execute package
                DTSExecResult result = goPackage.Execute();

                //write results to file
                m_streamWriter.WriteLine("Package Execution Results: {0} \n", result.ToString());

            }
            catch (Exception ex)
            {
                m_streamWriter.WriteLine("Error from dts: {0} \n", ex.ToString());
            }

it does not go to Exception it just fails.

The txt file just says it fails.

I can run the package on my own and it runs fine so the package is good. This is my first time writing a call to an ssis package from code so I may be doing it completely wrong...

Thanks in advance!

Yellowdog428 17 Light Poster

I wish that were true because it has a default of an empty string.

Thanks tho. I am looking into this more and I cannot seem to find a way to scan the entire dataset for dbnulls.

Man I wish this were a oneoff, I would just edit the file...lol

Thanks again, hopefully I can get this worked out.

Yellowdog428 17 Light Poster

Can someone please help.

I have a dataset that is populated with a csv or a tab seperated txt. I get the datset fine but when I try to insert into a table in sql with bulkinsert I am getting an exception.

The table does not allow nulls in the column. So what I need help with is scanning the dataset for a null value and replacing with an empty string or int value.

I spent some time looking around and found some code that will testif a column has a null value but I cannot seem to find the values and replace them.

Any help would be appreciated.

I will post some code a little later, just not on my work computer right now.

Thanks in advance

Yellowdog428 17 Light Poster

wow, I cant believe it was that easy. I guess I need reading lessons, just did what you said in the first post and everything works great.

also the toupper function saved me a lot of headache.

Thanks again for your help!
Jay

Yellowdog428 17 Light Poster

OK well I got the choice thing figured out, it was like you said, brackets and the char. I am having problems with the do while loop and the choice to exit the program.

The assignment is to create functions that count the number of consonants and vowels in a string while passing by a pointer. That much I got working fine it is this menu that is really giving me a hard time. I need to validate the input

function to show menu

void showMenu()
{
	cout << "Please select a menu option\n";
	cout << "A) Count the number of vowels in the string.\n";
	cout << "B) Count the number of consonants in the string.\n";
	cout << "C) Count the number of vowels and consonants in the string.\n";
	cout << "D) Enter another string.\n";
	cout << "E) Exit the program.\n";
	
}

then to verify input

while (choice < '1' || choice > '5')
		{
			cout << "Please enter A, B, C, D or E: ";
			cin >> choice;
		}

I am sure this is not right but cannot figure another way...

after this statement I need to put in the switch statement, but it should only run if the user dose not enter e so I added an if

if (choice != 'e' || choice != 'E')

the end of the program is the end of the do while for the menu driven program

} while (choice != 'e' || choice != …
Yellowdog428 17 Light Poster

I am working on an assignment for class and cannot for the life of me figure out how to use letters to choose a case for a switch statement.

Here is my code

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


// prototypes
void showMenu();
int getVowels(char*, int*, int);
int getLetters(char*, int);
int getConsonants(char*, int*, int, int, int);


int main()
{
	const int SIZE = 81;
	char string[SIZE];
	char *strPtr;
	int vowels = 0; 
	int *ptrVowels;
	int letters = 0;
	int consonants = 0;
	int *prtConsonants;
	char choice;

	
	cout << "Enter a string of letters no more than " << (SIZE - 1) << " charicters long: ";
	cin.getline(string, SIZE);
	do
	{
		strPtr = &string[0];
		ptrVowels = &vowels;
		prtConsonants = &consonants;
		
		consonants = 0; // reset consonants for run again
		vowels = 0; // reset vowels for run again
		letters = 0; // reset number of letters
		

		//display Menu 
		showMenu();
		
		//Get users choice
		cin >> choice;
		
		// validate Menu choice
		while (choice < 1 || choice > 5)
		{
			cout << "Please enter A, B, C, D or E: ";
			cin >> choice;
		}
		if (choice != 'e' || choice != 'E')
		{
		switch (choice)
			{
			case 'a': //get number of vowels in string
				{
					vowels = getVowels(strPtr, ptrVowels, vowels);
					cout << "The number of vowels in the string is: " << vowels << endl;
					break;
				}
				
			
			case 'b': // Get number of consonants
				{
					consonants = getConsonants(strPtr, ptrVowels, consonants, letters, vowels);
					cout << "The number of …
Yellowdog428 17 Light Poster

Students.major is what the assignment called for. Seemed silly to me too but thats what she wanted.

here is the assignment

This program will include error trapping with try and catch.

Put a throw in each function which gets user input and throw a string "Bad Major" if a Major of 0 is entered. The input functions are specified in 2, 4 and 7 below.

Create a global structure as follows:

struct Student

{

char Name[30];

float GPA;

int Major;

};

1. Now in main create 2 instances of that structure. Call them S1 and S2.

2. Create and call a function called StudentData:

S2 = StudentData( S1 );

The function receive as a parameter a reference to the structure( prototyping will handle this) and will return a reference to the structure. Use couts and cins for getting data from the user. (For testing puposes, change the data in S1 so that the GPA is 3.5 and the Major is 2.)

3. In main print the data stored in the structures S1 and S2 using cout.

4. Call a function called ChangeData with a pointer to S2 as the argument:

ChangeData( &S2 );

Change the data in S2 so that the GPA is 3.0 and the Major is 1. (Using these values for testing…)

5. Back in main print the data stored in the structure S2 using cout.

6. Now create an array of 2 structures in main. Call the array Students.

7. Create a function, GetStudents, which will …

Yellowdog428 17 Light Poster

OK so most can guess I am a student just now learning programming and starting out with C++.

I have tried many compilers and IDE's and have settled on Eclipse for now. I do not want to start a What compiler/IDE do you use, but I am trying to figure out each one I try as much as I can.

So I noticed that an assignment I was working on would compile and run on Microsoft Visual C++ 6.0 but not Eclipse.

The program was to teach us how to throw an exception. When Eclipse would hit that line in the code it would quit the program, but Visual C++ would run the program the whole way through.

here is the code (Sorry about the length)

//Written by Jason Stabins
//March 19, 2008
//Chapter 16
//Programming Challange throw

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

//declare global size for name
const int NAME_SIZE = 30;

//Hold student info
struct Student {
    char Name[30];
    float GPA;
    int Major;
};

//Prototypes
Student StudentData(Student &S1);
Student ChangeData(Student &S2);
Student GetStudents(Student students[], int SIZE);
Student printStudents(Student students[], int SIZE);

int main() {
    Student S1, S2; //Two student structs
    
    //exceptions
	cout << "Enter the first students information and I will copy it into";
	cout << " the second.\n DO NOT ENTER ZERO FOR THE MAJOR!\n\n";

    try
    {
    S2 = StudentData(S1);
        
    cout << "Student 1 name:\t\t" << S1.Name << endl;
    cout << "Student 1 GPA:\t\t" << S1.GPA << endl;
    cout << "Student 1 …
Yellowdog428 17 Light Poster

er...

look at it this way

when there is a = sign remember that it is an assignment operator not an "equal" sign

anything on the left is assigned to what is on the right

But what about the "x=y" part, followed by "x=10"???? Doesn't that say "x has same value as y, and x is now 10" Doesn't that mean that y will also be 10??

Looks like you read it wrong.
the only variable assignment he made was y = x

cheers

Yellowdog428 17 Light Poster

You know whats funny, I have posted a few times here for homework help here on the forums and have had nothing but great help. I think the problem people run unto is when they try to trick you guys.

here is a hint for all the people out there trying to get help with homework.

1. Explain the problem in detal
2. Be upfront "I have an assignment and here is the problem"
3. Post the code that you are working on
4. Do NOT reply to bump your thread every hour. If there is someone that can help and wants to they will. Bump after a day or so if you need to.
5. Keep working on it.

Also read this link supplied at the top of the page
http://www.daniweb.com/forums/announcement8-2.html

As I understand it there are a lot of good programmers here and they are willing to help, just be respectful!
"Here is a programming challange" titles are not going to get you anywhere.

Thank you everyone here. You are all very helpful keep up the great work!

Jay

VernonDozier commented: Well said. +2
Salem commented: Bravo!!!! +15
Yellowdog428 17 Light Poster

Sometimes it is the simplest things...

Thanks for your help!

I got my loop fixed. I changed the input a bit to fix the keyboard buffer, how does this look?

cout << "Player " << i+1 << " info\n";
        cout << "Enter the name of the player :";
        cin.getline(player[i].name, NAME_LENGTH);
        cout << "Enter the players number :";
        cin >> player[i].number;
        cout << "Enter the players points :";
        cin >> player[i].points;
        cout << "------------------------------\n";
    	cin.ignore();

I used getline so a space is available for a full name.

Thanks again!

Yellowdog428 17 Light Poster

for some reason I cannot add integers in an array of structures. here is the code.

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

const int SIZE = 5;

struct playerInfo {
    char name[30];  //Players name
    int number;
    int points;
};

int main()
{
    int total = 0;   // to hold total points scored
	
    playerInfo player[SIZE];
    
    cout << "Enter the information for five players:\n\n";
    
    for (int i = 0; i < SIZE; i++)
    {
    	cout << "Player " << i+1 << " info\n";
        cout << "Enter the name of the player :";
        cin >> player[i].name;
        cout << "Enter the players number :";
        cin >> player[i].number;
        cout << "Enter the players points :";
        cin >> player[i].points;
        cout << "------------------------------\n";
    }
    
    //calculate total
    for (int i = 0; 0 < SIZE; i++)
    {
    	total = (player[i].points + total);
    }

    //showResult
    
    cout << "Here is a list of players and thier scores\n";
    cout << "------------------------------------------\n";
    for (int i = 0; i < SIZE; i++)
    {
        cout << player[i].name << "\tPoints:" << player[i].number << "\tScore:" << player[i].points << endl;
    }

    cout << "The total points scord by the team is :" << total << endl;
    
return 0;
}

If I comment this out

//calculate total
    for (int i = 0; 0 < SIZE; i++)
    {
    	total = (player[i].points + total);
    }

the program will run fine without giving me the total obviosly. This code crashes the program...

I also tried

total += player[i].points

with no luck.

any help would be great!

Yellowdog428 17 Light Poster

Thanks!

Sometimes it is the easiest things...

Cheers!

Yellowdog428 17 Light Poster

Wow, I am having huge problems passing values between functions and wrapping my head around pointers.

For some reason when I tried to return values from functions they would not pass and when I tried putting pointers in the place, passing them kept giving me compiler errors. Now I have no errors but my values are not passing correctly.

Any help I could get with this code would be great!

#include<iostream>

#include<iomanip>

using namespace std;



//function prototypes

void displayScores(int, int[]);

void sortString(int, int[]);

double averageScore(int, int, int[]);

int dropLowest(int, int, int[]);



int main()

{

	int count = 0,

		arraySize = 0,

		*array,

		lowest = 0,

		*lowPtr = &lowest;

	double average = 0.0;

		

	

	cout << "How many test scores would you like to enter? ";

	cin >> arraySize;

	

	//alocate memory

	array = new int[arraySize];

	

	//collect data

	for (count = 0; count < arraySize; count++)

	{

		cout << "Test " << (count + 1) << " score : ";

		cin >> array[count];

		

		//verify input

		if (array[count] < 0)

		{

			cout << "Please enter a score greater or equal to zero!\n";

			cout << "Enter the " << (count + 1) << " test score : ";

			cin >> array[count];

		}

	}

	//sort the array

	sortString(arraySize, array);

	

	//display scores

	displayScores(arraySize, array);

	

	//droplowest score

	dropLowest(arraySize, *lowPtr, array);

	

	// display lowest

	cout << lowPtr << "Is the lowest score\n" ; 

	

	//calculate average

	averageScore(arraySize, *lowPtr, array);

	

	//display scores

	displayScores(arraySize, array);

	cout << "The average is " << average << endl;

	

	//delete memory

	delete [] …
Yellowdog428 17 Light Poster

Thanks guys!

I used the strcpy command like dougy83 suggested!

void sortString(double rainfall[], char month[][10], int MONTHS)
{
	double swapRain = 0,
		highest = 0;
	char swapMonth[10],
		highestMonth[10];
	
	for (int startIndex = 0; startIndex < (MONTHS - 1); startIndex++)
	{
		highest = rainfall[startIndex];
		swapRain = rainfall[startIndex];
		
		for (int count = startIndex + 1; count < MONTHS; count++)
		{			

			if (rainfall[count] > highest)
			{
				highest = rainfall[count];
				strcpy(highestMonth, month[count]);
				swapRain = rainfall[startIndex];
				strcpy(swapMonth, month[startIndex]);
				rainfall[count] = swapRain;
				strcpy(month[count], swapMonth);
				rainfall[startIndex] = highest;
				strcpy(month[startIndex], highestMonth);
			}
		}
	}
}

works like a charm!

Yellowdog428 17 Light Poster

Thank you for your help!

Problem is I have not learned structures yet....

is there another way to do it without them?

Thanks again

Yellowdog428 17 Light Poster

Need some help.

I have an assignment that calls for the sorting of two arrays. One is an array of doubles, the other chars (two dimensional). I cannot figure it out for the life of me.

Here is the whole program.

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

//Function Prototypes
double sumRain(double[], int);
double getHighest(double[], int);
double getLowest(double[], int);
void sortString(double[], char[][10], int);
void displaySort(double[], char[][10], int);
void displayResults(double total, double average, double lowest, double highest);

int main()
{
	const int MONTHS = 12;
	double	rainfall[MONTHS] = {0},
			total = 0,
			average = 0,
			highest = 0,
			lowest = 0;
	char month[MONTHS][10] = {"January",
							"Febuary",
							"March",
							"April",
							"May",
							"June",
							"July",
							"August",
							"September",
							"October",
							"November",
							"December"};

	//Collect the rainfall for each month and store the data in an array
	for (int count = 0; count < MONTHS; count++)
	{
		cout << "Please enter the the rainfall for " << month[count] << endl;
		cin >> rainfall[count];

		if (rainfall[count] < 0)
		{
			cout << "You MUST enter an amount greater or equal to zero!\n";
			cout << "Please enter the rainfall for the " << month[count] << " month.\n";
			cin >> rainfall[count];
		}
	}

	//Calculate the total rainfall
	total = sumRain(rainfall, MONTHS);
	
	//Calculate the average
	average = total / MONTHS;

	//Find the month with the highest rainfall
	highest = getHighest(rainfall, MONTHS);

	//Find the month with the lowest rainfall
	lowest = getLowest(rainfall, MONTHS);
	
	//Display results
	displayResults(lowest, highest, average, total);
	
	//Sort The strings
	sortString(rainfall, month, MONTHS);
	
	//display the sorted strings
	displaySort(rainfall, month, MONTHS);
	
	
	return 0; …