rogenie 20 Light Poster

Thanks for inputs. still playing with it.

rogenie 20 Light Poster

I am using the latest phpmyadmin. I have a database and within it is a whole bunch of tables. I want to load a semicolon delimited text file but it doesn't seem to work. Here is the sample of my text file where 55 is the field id. Field title is the country name and the last is the ordering of my countries.

55;Portugal;178
55;Puerto Rico;179
55;Qatar;180
55;Reunion;181
55;Romania;182
55;Russia;183

All i am trying to do is populate the country list so I dont have to enter it manually. Is there any other way of doing this? Please help!

Thank you so much

rogenie 20 Light Poster

Hi guys. Thanks. I wanted the user to enter as much data as they want and put it in a listbox. then it will end when the calculate average button is clicked.

Why does it do infinite loop? If I dn't do it that way, then how can I make the user input as much number as they want?

rogenie 20 Light Poster

Can someone explain to me why this code do not try to perform the loop? It just crashes my program:(

Private Sub btnCommission_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommission.Click
        Dim strComAmount As String
        Dim decComAmount As Decimal
        Dim decAverageCom As Decimal
        Dim decTotalOfAllCom As Decimal = 0D
        Dim intNumberOfEntry As Integer

        'convert textbox data into decimal
        strComAmount = Me.txtCommission.Text
        decComAmount = Convert.ToDecimal(strComAmount)

        'Initiate the loop
        While decComAmount > 0
            Me.lstTally.Items.Add(decComAmount)
            intNumberOfEntry += 1
            decTotalOfAllCom += decComAmount
        End While

        'Calculate Average
        decAverageCom = decTotalOfAllCom / intNumberOfEntry

        'Display Total and count

        Me.lblTotal.Text = decAverageCom.ToString("C")
        Me.lblCount.Text = CStr(intNumberOfEntry)
        Me.lblAverage.Text = decAverageCom.ToString("C")
        If decComAmount < 0 Then
            MessageBox.Show("Please enter more than one dollar")
        End If


    End Sub
rogenie 20 Light Poster

in a post quick reply there is not preview button?? Also there is no CODE tag in there. Only quote

rogenie 20 Light Poster

I got the problem solved by the way.. I read your last post over and over again. below is my final code...

const int NUM_NAMES = 20, SIZE = 17;

//function prototype
void selectionSort( char array[][SIZE], int size );
int binarySearch( char array[][SIZE], int numelems, char value[SIZE] );


int main()
{
    char names[NUM_NAMES][SIZE] = {
            "Collins, Bill", "Smith, Bart", "Allen, Jim",
            "Griffin, Jim", "Stamey, Marty", "Rose, Geri",
            "Taylor, Terri", "Johnson, Jill",
            "Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
            "James, Jean", "Weaver, Jim", "Pore, Bob",
            "Rutherford, Greg", "Javens, Renee", 
            "Harrison, Rose", "Setzer, Cathy",
            "Pike, Gordon", "Holland, Beth",  };
 
    int result;
    char nameString[SIZE];
 
    selectionSort( names, NUM_NAMES );
 
    cout << "Enter name: ";
    cin.getline( nameString, SIZE );
 
    result = binarySearch( names, NUM_NAMES, nameString );
 
    if( result == -1 )
        cout << nameString << " is not in the list.\n";
    else
        cout << names[result] << " found.\n";
 
    return 0;
}
//displayStrings function
void displayStrings( char array[][SIZE], int size )
{
    for( int index = 0; index < size; index++ )
        cout << array[index] << endl;
}

//selectionSort function
void selectionSort( char array[][SIZE], int size )
{ 
    int startScan, minIndex;
    char minValue[SIZE];
 
    for( startScan = 0; startScan < (size - 1); startScan++ ) 
   {
 
        minIndex = startScan;
        strcpy( minValue, array[startScan] );
 
        for( int index = startScan + 1; index < size; index++ )
        {
            if( strcmp( array[index], minValue ) < 0 ) {
                strcpy( minValue, array[index] );
                minIndex = index;
             }
        }
 
        strcpy( array[minIndex], array[startScan] );
        strcpy( array[startScan], minValue );
 
    }
	 
}

//The binarySearch function …
rogenie 20 Light Poster

Hi thanks for all the input. I dropped out of the class and decided to go the the classroom instead on spring. I will make sure to pest on my teacher anytime I don't understand anything. This is just too hard learning on my own and hoping to get some answers from various forums. I could put a homewrk together but I am not really understanding it fully:=)

rogenie 20 Light Poster
//The binarySearch function
int binarySearch( char array[][SIZE], int numElems, char value[SIZE] )
{
    int first = 0,
        last = numElems - 1,
        middle,
        position = -1;
    bool found = false;
    while (!found && first <= last)
    {
        middle = (first + last) / 2;
        if (strcmp(array[middle], value) == 0)
        {
            found = true;
            position = middle;
        }
        else if (strcmp(array[middle], value) > 0)
            last = middle - 1;
        else
            first = middle + 1;
    }
    return position;
}

thats what I end up with and still digesting little by little. I just dont get this comparing C-strings stuff.

rogenie 20 Light Poster

ohhh, Hmm I am comparing strings.. why am I using int?? I should use strcpy?? Let me try

rogenie 20 Light Poster

I can't be possibly comparing it wrong because this is what the book said??

rogenie 20 Light Poster

Look at how you're doing the comparisons in binary search function. What's really being compared?

binarySearch function is suppose to start searching from the middle of the array then go up. if the value the user entered is not there, then start searching again from the middle of the array going down. To my understanding what is really being compared here is the element from the middle of the array to the last element? the same thing as with the binary search going from the middle element of the array going down. Yea? I don't understand well.. We just started with functions and this is still very new and fresh to me

rogenie 20 Light Poster

Probably because you returned the value you didn't want.

Because you didn't explain
1) what you wanted
2) what the program did
3) where the error is
there's not much to tell you.

I guess you didn't understand the information listed in the post at the top of the forum titled "Read Me: Read This Before Posting", eh?

This is suppose to ask the user to type in the name and display the name if it is inside the array. Otherwise a message displays "The name is invalid". I am using binary search (binarySearch function) to search through the array and sorting the array first using selection sort (selectionSort function).

rogenie 20 Light Poster

here is my code. I don't know why it always returns the value that i do not ask for.?? This code display the name I typed in if it is inside the array.

//this will sort strings using selection sort
#include <iostream>
using namespace std;

const int NUM_NAMES = 20, SIZE = 17;

//function prototype
void selectionSort( char array[][SIZE], int size );
int binarySearch( char array[][SIZE], int numelems, char value[SIZE] );


int main()
{
    char names[NUM_NAMES][SIZE] = {
            "Collins, Bill", "Smith, Bart", "Allen, Jim",
            "Griffin, Jim", "Stamey, Marty", "Rose, Geri",
            "Taylor, Terri", "Johnson, Jill",
            "Allison, Jeff", "Looney, Joe", "Wolfe, Bill",
            "James, Jean", "Weaver, Jim", "Pore, Bob",
            "Rutherford, Greg", "Javens, Renee", 
            "Harrison, Rose", "Setzer, Cathy",
            "Pike, Gordon", "Holland, Beth",  };
 
    int result;
    char nameString[SIZE];
 
    selectionSort( names, NUM_NAMES );
 
    cout << "Enter name: ";
    cin.getline( nameString, SIZE );
 
    result = binarySearch( names, NUM_NAMES, nameString );
 
    if( result == -1 )
        cout << nameString << " is not in the list.\n";
    else
        cout << names[result] << " found.\n";
 
    return 0;
}
/*displayStrings function
void displayStrings( char array[][SIZE], int size )
{
    for( int index = 0; index < size; index++ )
        cout << array[index] << endl;
}*/

//selectionSort function
void selectionSort( char array[][SIZE], int size )
{ 
    int startScan, minIndex;
    char minValue[SIZE];
 
    for( startScan = 0; startScan < (size - 1); startScan++ ) 
   {
 
        minIndex = startScan;
        strcpy( minValue, array[startScan] );
 
        for( int index = startScan + 1; index < size; index++ )
        {
            if( strcmp( array[index], minValue ) < 0 ) …
rogenie 20 Light Poster

Okay never mind I figured it out. thanks....

rogenie 20 Light Poster

Okay I made changes. Here is my code but the ouput is wrong. Hmmmmmm....

//this will let the user enter 10 values and 
//store them into an array. After that
//sort it out and cout the largest and the smallest number entered

#include <iostream>
using namespace std;

int main()
{
    const int NUM_ARRAY = 10; //number of numbers to be entered
    int numHolder[NUM_ARRAY]; // where the numbers will be stored
    int count; //accumulator
    int highest; //highest number
    int lowest; //lowest number

    //input the numbers
    for (count = 0; count < NUM_ARRAY; count++)
    {
        cout << "Please enter series of numbers"
        << (count + 1) << ": ";
        cin >> numHolder[count];
    }
    //show the numbers entered
    cout <<"The numbers you entered are: \n";
    for (count = 0; count < NUM_ARRAY; count++)
        cout << numHolder[count]<< endl;


    for (int count = 1; count < NUM_ARRAY; count++)
    {
        highest = numHolder[0];
        if (numHolder[count] > highest)
            highest = numHolder[count];
    }

    //pick the highest number
    cout << "The highest is: " << highest << endl;

    return 0;

}
rogenie 20 Light Poster

Why does the code below stop executing after displaying all the numbers stored in an array?

//this will let the user enter 10 values and 
//store them into an array. After that
//sort it out and cout the largest and the smallest number entered

#include <iostream>
using namespace std;

int main()
{
	const int NUM_ARRAY = 10; //number of numbers to be entered
	int numHolder[NUM_ARRAY]; // where the numbers will be stored
	int count; //accumulator
	int highest; //highest number
	int lowest; //lowest number

	//input the numbers
	for (count = 0; count < NUM_ARRAY; count++)
	{
		cout << "Please enter series of numbers"
		<< (count + 1) << ": ";
		cin >> numHolder[count];
	}
	//show the numbers entered
	cout <<"The numbers you entered are: \n";
	for (count = 0; count < NUM_ARRAY; count++)
		cout << numHolder[count]<< endl;

	//pick the highest number
	cout << "The highest is: ";
	highest = numHolder[0];
	for (int hcount = 0; hcount < numHolder[count]; hcount++)
	{
		if (numHolder[count] > highest)
			highest = numHolder[count];
	}
	

return 0;
	
}
rogenie 20 Light Poster

Oh I see what you are saying. Every time the loop iterates, the average calculation will also calculate since it is a part of a loop. Instead having it outside the loop makes it look better and would be a good programming practice:)

Ancient Dragon commented: Exactly! Now you have the right idea. +20
rogenie 20 Light Poster

Hi thanks. I tried putting the average calculation inside the while loop and it still worked. The line 26 is the one giving problem when I was trying to find out the total of numbers inside the file. Thanks.

rogenie 20 Light Poster

well here is the code. It outputs 516 instead of 200 random numbers I am trying to read off random.txt file.

//This will read the file random.txt,
//then it will tell you the number of numbers in the file
//it will sum it up 
//and give the average number

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

int main()
{
	ifstream inputFile;
	int number;
	int totalNumber = 0;
	int sumNumber = 0;
	double average;

	inputFile.open("C:\\random.txt");
	if (!inputFile)
		cout << "Error opening file\n";
	else
	{
		while (inputFile >> number)
		{
			//number of numbers
			for (totalNumber = 0; totalNumber <= number; ++totalNumber)
				totalNumber++;

			//sum of numbers
			sumNumber = sumNumber + number;

			//average
			average = sumNumber/totalNumber;
		}
		inputFile.close();
		cout << "There are " << totalNumber << " in random.txt file" << endl;
		cout << "The sum of all these numbers is: " << sumNumber << endl;
		cout << "The average is: " << average << endl;
	}
	return 0;
}
rogenie 20 Light Poster

why does this file outputs 516?? The value of numbers is being read from random.txt that has 200 random numbers in it. I was expecting this to output 200 and NOT 516.. whats up with this?

while (inputFile >> number)
		{
			//number of numbers on the  file
			for (totalNumber = 0; totalNumber <= number; ++totalNumber)
				totalNumber++;
rogenie 20 Light Poster

Hi Duos. Thanks for the input but I don't know what your header means. We are not on that part yet and all I have gone so far with the class and books are the very basic like loops, if else, very few functions.

while (true) {
std::cin >> s;
if (s.empty()) break;
i = std::atoi( s.c_str() );

that code, I would not know how to read it.

rogenie 20 Light Poster

I am glad i found this forum by the way:) There is so much to learn and read here.. thank you

rogenie 20 Light Poster

thats true that people doesn't learn if you feed them the code - ONLY if they are not serious about learning it and just want to pass the course. In my case, this homework deadline was first week of October. Up to now I still don't get it and I am still trying to get a grip of it. I spend 4 to 6 hours a day learning C++. Reading the books over and over again. The prolem is, the book says so much and doesn't show it in action (that is code samples). People will just possibly quit and give up especially for someone like me that never encountered <iostream> in my english vocabulary - if you know what I mean:). But if you start something up where they could sit there and analyze the code, then try to understand, then as we go we could refer back to the code and figure out what did I do wrong and learn from there. To me anyway thats how I learn. :=)

So why did Trace put a break; on line 23? Also, why did you use == on line 22? Why can't we not use = for assigning -99 to it? I dont understand those part.

rogenie 20 Light Poster

Ughh, I dont get it. I have a handful of numbers that the user entered sitting inside the variable numbers. Now, I need to be able to see those numbers and assign the big one to maxValue. But this code doesn't even attempt to assign anything on maxValue! why?

//declare variables
	int numCount = 1;		// number accumulator
	int numberEntered;      //to hold the numbers entered
	int minValue;
	int maxValue;

//ask for number inputs
	cout << "Please enter random numbers\n";
	cout << "I will sort them out and tell you\n";
	cout << "the largest and the smallest number you entered\n";
	cout << "When you are done just enter -99 so I can process your inputs\n\n";

//enter the sentinel -99 to end the number inputs

	while (numberEntered !=-99)
	{
		numCount += numberEntered;
		numCount++;
		cout << "Enter random number: ";
		cin >> numberEntered;
	}
		numCount = maxValue;	
		cout << "Big number: " << maxValue << endl;
rogenie 20 Light Poster

this is not working at all. the user should be able to enter as many numbers as he wants and then enter a SENTINEL when he is done. Then the program should look through the numbers he entered and come back and tell him what is the highest number he entered and what is the lowest number he entered.

rogenie 20 Light Poster

that code might work if we set a specific number of random integers to compare. What if we let the user to enter as many integers as we want? or only 5 numbers? We can't set a constant variable with this am I right?

rogenie 20 Light Poster

Gosh I am so sorry, what do you mean by extrimum?

rogenie 20 Light Poster

The chapter I am right now does not cover array so I dont think I am able to use arrays with this. :(

rogenie 20 Light Poster

Okay, I got abotu 5 problems solved today and I am on the hardest part! Basically my code ask the user to enter series of random numbers and then use sentinel to mark the end of numbers needed to be entered. Now I want to be able to tell my user the largest and the smallest number she/he entered. Is there a function that can do this? like a sort or something? Here's my code:

//This program lets the user enter series of random numbers
//Enter -99 to end the series
//Display the largest and smallest number entered
#include <iostream>
using namespace std;

int main ()
{
//declare variables
	int numCount = 1; // number counter
	int numbers; //to hold the numbers entered
	int numAccum; // accumulator

//ask for number inputs
	cout << "Please enter random numbers\n";
	cout << "I will sort them out and tell you\n";
	cout << "the largest and the smallest number you entered\n";
	cout << "When you are done just enter -99 so I can process your inputs\n\n";
	cout << "Enter random number " << numCount << ": ";
	cin >> numbers;

//enter the sentinel -99 to end the number inputs

	while (numbers !=-99)
	{
		numAccum += numbers;
		numCount++;
		cout << "Enter random number " <<numCount << ": ";
		cin >> numbers;
	}

//sort out the numbers and pull out the largest and the smallest
	
	cout << "The largest number is: \n";
         WHAT FUNCTION DO I USE HERE??? OR ANY jumpstart on looping this?



return …
rogenie 20 Light Poster

so num IS the accumulator? why do we have to assign something in it? why can't it just grab the value of maxNum and increment then store the value to total? I don't clearly understand but I thank you so much for helping me. Still studying the code you provided.

rogenie 20 Light Poster

this doesn't work either. an example is if the user enter 3 the total should display 6 (1+2+3 = 6). What I dont understand is how the initializer really works on the first parameter of for loop?? we have to have an accumulator or a counter some place so that as the number entered by the user increments, it also adds it up.

rogenie 20 Light Poster

I simply dot get it. heres my understanding

user enter a number
number entered get stored in variable maxNum
then get that number and sum up the total. HOW?
step1: initialize 0 to num
step2: compare if num is less than or equal to maxNum (the number the user entered)
step3: increment the maxNum from 1 to whatever number the user entered.
step4: total up the sum of maxNum (maxNum +=)
cout the total! is there a missing step? grrrrrr!!! pls help me understand! this i my homework and due tonight at 11...

rogenie 20 Light Poster

This is a very simple app I am trying to do. How else would sum up the total of the number the user entered? Example if the user enters 10, the loop will find the sum of 1,2,3,4,5.....10. Here is my code and I spent few hours on to come up with this simple code.

//this will add up the number you entered
# include <iostream>
using namespace std;

int main()
{
	int num; //to hold the number to be sumed up
	int input; //this is an accumulator
	int maxNum; //the maximum number the user entered
	int total; //this will hold the total of the number the user typed in
 
cout << "Enter the number and I will add them up<<\n";
cin >> maxNum;

for (num=1; maxNum=1; input++)
{
	cout <<"You entered" <<maxNum<< endl;
	cout <<"See the total below" << endl;
	cout << (total += input) << endl;
	maxNum++;
}
	return 0;
}

the book says I can use the for loop if the number of iteration is known. In this case the iteration depends on the number the user entered which is stored in maxNum variable. Which operator I am using is wrong here or the whole structure of my code is messed up? Please help!