Duki 552 Nearly a Posting Virtuoso

Please remember to use code tags. It makes helping you much easier. I think you need to adjust how you're closing your { } throughout your program. What specifically isn't working now?

Edit: What did you change from last time? This looks exactly the same ... ?

Duki 552 Nearly a Posting Virtuoso

Why do you have a nested while() and then another nested switch()? Why not just loop again after detecting the first invalid input? I suspect this is why you're receiving the same prompt, twice. You're only returning from the nested while(), not the overall while().

Consider changing the default case in your first switch() to re-prompt the user ... I'm betting this will get you what you're looking for.

>>Could someone help me. Get rid of this problem.
This isn't what we do.

>>Could someone help me get rid of this problem?
This is what we do.

Duki 552 Nearly a Posting Virtuoso

What do you have so far?

Duki 552 Nearly a Posting Virtuoso

I think this site will help you a lot. Don't give up!

Duki 552 Nearly a Posting Virtuoso

Have you tried doing this in one file? Maybe that will help you understand what's going on. You can't declare an object in one file (or a method for that matter) and then expect to be able to use/change it somewhere else. Your objects are not globally accessible (unless declared as such).

Have a look at how the call stack works - it's a challenging topic if you're new to programming, but will help you tremendously I think.

Duki 552 Nearly a Posting Virtuoso

Not to be picky here, and it has very little to do with the question you're actually asking, but don't get in a habit of meaningless variable and function names (e.g., v, n, xVec, asum, etc.). In fact, the opposite is a more industry accepted approach. I made the mistake during my schooling of, in an attempt to get the program working, not worry about what I called my variables because I knew what they meant and that's all that mattered. However, when I started working on larger more independent projects (projects that might actually be picked up by another programmer one day or that has over 500 lines of code) I found myself continuing my old habits without realizing it sometimes.

Now, while you're learning and in school, start doing the opposite - over describe your variables. It's ok for your professor to jot down meaningless variables in class, as they're merely for demonstration. As for your programs, attempt to be as descriptive as possible with both your functions and variable names.

Some examples from the software I debug daily:

FfsApportionmentDocumentAmendmentDataEntryCritic
FfsAssetDetailAcctgLineIdentityPtr

GetRuleCustomerAccountTreatment()
GetItemLineOriginalAmount()
AddDocumentTypeDefinedAccountingLineCodeColumns()

Just some food for thought.

Duki 552 Nearly a Posting Virtuoso

Whoa whoa wait... No. :)

You can still add Student objects to your list. You just need to modify your Student class to have the new data you need.

e.g.,

string FirstName;
string LastName;
etc.
etc.

Now, if you are wanting to both declare a new Student and add it to your list, you are correct in your new parameter list.

Duki 552 Nearly a Posting Virtuoso

You're closer than you think with this.

void getStudent (string student)
{ 
     studentnode* current;
     current = start; 
     while(current!=NULL)
     {   
         if(current->data == student)   
         {    
               cout << "The Specified Student Has Been Found: "<< endl;
               cout << student <<endl;  
                 break;  
                 }  
                  current = current->next;  
                  }
                  }

       

       //display all the items in the list
       void print()
       {
            studentnode * current;
            current = start;
            
           //loop through all nodes, each time doing something
           while(current != NULL )
           {
               //display the data of the current node
               cout << current->data << endl;
               
               //move current to next node
               current = current->next;               
           }     
       }
};

What if you modified the parameter to getStudent(int id) - then you could, instead of cout << student << yada, just do current->printData(), right?

Duki 552 Nearly a Posting Virtuoso

Have you dealt any with operator overloading?

I'm not sure exactly what you're asking though - are you wanting to add members of the same class (e.g., Create one large string of "Student - University - ID") or are you wanting to add members from other classes (e.g., string temp = StudentA.name + StudentB.name)?

Duki 552 Nearly a Posting Virtuoso

I'm quite sure Fbody's post will do what you want - he's just not going to do everything for you.

e.g.,

const int COUNT = 5;
Speaker myArray[COUNT] = [0, 1, 2, 3, 4 };

void displayInfo(int requestedItem) {
  if (requestedSize < COUNT)
    cout << myArray[requestedItem - 1].showName();
    etc.
    etc.
  else
    cout << "You have requested an invalid element." << endl;
}

He's merely demonstrating the usage of arrays to access your methods. What you're referring to isn't exactly what you want to do.

for() - Do this for every element
if() - Do this for the selected element

What I would suggest is remove your if()'s and try using switch()

Fbody commented: thx +2
Duki 552 Nearly a Posting Virtuoso

What he meant to say was,

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <cmath>

using namespace std;


int main()
{
	char ans;
	srand(time(0));
	int randomNumber = rand() % 10+1;
	bool guessed = false;

    do
    {
		guessed = false;
		system ("cls");
		cout << "\tThe Number Guessing Game\n\n";
                randomNumber = rand() % 10+1;

		do
		{
			int guess = 0;
			
			cout << "Enter your guess (#1-10): ";
			cin >> guess;

			if (guess < randomNumber)
				cout << "Your guess was too low\n\n";

			if (guess > randomNumber)
				cout << "Your guess was too high\n\n";

			if (guess != randomNumber)
				cout << "Try Again\n";

			if (guess == randomNumber)
			{
				cout << "\nCongratulations! You've guessed the number.\n\n";
				guessed = true;
			}
		}while (!guessed);



	cout <<"You want to try again??";
	cin >> ans;

    } while ((ans=='y')||(ans=='Y'));

    cout <<"Thank You!!";
    getch();

  return 0;
}

You don't want to seed srand() more than once during your program - just a bad habit to get into. You only need to seed it once.

Duki 552 Nearly a Posting Virtuoso

I'm not sure - I don't use Visual C++. I'm sure someone with more experience will hop on soon.

Duki 552 Nearly a Posting Virtuoso

Perhaps something like,

Int32 myInt = 0;
if ( System::Text::RegularExpressions::Regex::IsMatch(myTextBox->Text, 
	"^[-0-9]*.[.0-9].[0-9]*$") )
{	
	myInt = System::Convert::ToInt32 ( myTextBox->Text );				
}
else
{
	MessageBox::Show("Not a number");
}

This is an excerpt from another message board on the same topic.

Duki 552 Nearly a Posting Virtuoso

>It is due you are trying to access a value pointed by pointer outside the scope.

So... did you bother testing your code before posting it? Sure it prints now - but perhaps pointing member variables to the same memory location throughout the entire program isn't the best idea (i.e., char n[21]).


@o/p - With the suggestions from the previous post, you should see how adding a few more variables to your program should fix things up. However, keep in mind that changing the values of your main() variables (assuming you'll be doing char arrays) will in fact change the value of your members.

E.g.,

//pseudo
char temp[10];

cout <<"\n Enter the first name of 1st employee:: ";
e1.setName(gets(n));			
cout <<"\n Enter the last name of 1st employee:: ";
e1.setLastName(gets(n));

Sample Input:
Billy
Bob

The above code will indeed change your employee's last name to Bob, but will also change your first name to Bob.


edit> I have to agree with tkud. Much cleaner than trying to use char[]

Duki 552 Nearly a Posting Virtuoso

Instead of doing a switch() on id, how about doing a switch on the menu choice? Then, it would be very simple to create a few functions that take the id as a parameter to do what you want.

e.g.,

//pseudo
switch(menu_choice)
{
case 1:
	CheckBalance(id);
	break;
case 2:
	Withdraw(id);
	break;
case 3:
	Deposit(id);
	break;
case 4:
	break;
}

This way, you're not "setting" anything (i.e., "//Set the account to the selected account values."). You can just pass an ID to your functions, which will then determine what action to take on which account. Unless I'm misunderstanding what you're trying to do?

>As another tip - try to keep your main() relatively small. I would suggest creating a couple of functions to InitializeAccounts() & ExecuteCommand(choice), or something similar. This makes accessing your data a little different, but it's worth the extra work.

Duki 552 Nearly a Posting Virtuoso

Good to hear - don't forget to mark your post as solved in case others may need to reference it.

[and for self esteem reasons]

Duki 552 Nearly a Posting Virtuoso

>>you need to adjust your prompt to fit the requirements of the assignment.

Pay attention to his suggestion here. The user needs to know what they're inputting. Try changing your prompt to something more like,

Give me a number (0-25):

To get even a little fancier here, you could do something like,

int main ()
{

	int num; // input
	string ary[26] = {“Zero”,"One", "Two", … , "Twenty-Five"};

	bool invalid_input = true;
	while(invalid_input)
	{
		cout << "Give me a number: " << flush ;
		cin >> num;

		if (num>=0&&num<=25)
		{
			for (int i = 0 ; i <= num ; i++)
				cout << i << "\t - \t" << ary[i] << endl ;

			invalid_input = false;
		}
		else
		{
			cout<<"Invalid!"<<endl;
			 invalid_input = true;
		}
	} 

	return 0;
}

This way you could loop until you get a valid input.

Duki 552 Nearly a Posting Virtuoso

My post overlaps somewhat with fbody, but should help answer your remaining questions.

edit> noticed a typo in my first post - modified part about the for() loop slightly.

Duki 552 Nearly a Posting Virtuoso

edit> sorry for double post fbody :P

----> string ary[26] = {"Zero","One", "Two", "Three", ... , "Twenty-Five"}
You can do that also, it doesn't matter.

It's doing this,

//pseudo
ary[25]  .....  this equates to 

ary[0]
ary[1]
ary[2]
.
.
.
ary[23]
ary[24]

//THEN - compiler does this

ary[0] = "whatever is first"
ary[1] = "whatever is next"
.
.
.

//So - you could actually do this

ary[25] = {"Ten", "Eleven", "Seven", "Horse", "Chair", ...}

//and be completely legal as far as the compiler is concerned.

cout << "Give me a number: " << flush ;
For lack of a detailed description, flush as opposed to endl just sets the cursor at the end of your line to make input cleaner. So instead of,

Please enter your name:
Bobby Joe

You can have something like,

Please enter your name: Bobby Joe

-----> for (num=0,ary=0;num<=25,ary<=26;num++,ary++)
Not at all, sorry. Here's a hint - you only use one statement in each blank. So take out everything and re-look at my for() loop. Remember, if you start at 0 and your array is only 25 items large, your indexing doesn't go all the way to 25, right? So even in the case of trying to access ary[25], it would blow up.

Your for loop should look like this

for (int i = 0 ; i < ... ; i++)

Question: ary[26]?
Sorry, wrong again here. You want to …

Duki 552 Nearly a Posting Virtuoso

>Also Duki, I think you switched from Nodes to Toms on accident. And arrays initializer lists use curly braces, not parentheses.

Sure did - thanks.

Duki 552 Nearly a Posting Virtuoso

Hey Tom, you can do this two ways. The easiest way would be to use a vector instead of an array:

vector<Node> Tom(5, Tom(width));  //5 Tom objects calling Tom(width)

The other way, if you want to (a) specify the parameters for each object or (b) continue using arrays:

Node Tom[5] = ( Tom(1), Tom(2), Tom(3), Tom(4), Tom(5) );

Hope this helps

Duki 552 Nearly a Posting Virtuoso

I agree with embooglement. You functions should rarely (if ever) be that large. The general rule I go by is, if it takes more than a sentence or two to describe the function, it's too long and should be broken up. This also plays along with OOD in that, you want your code to be extensible and reusable. Creating many smaller functions rather than a few large functions increases the probability that you'll be able to use those functions later for something else.

Example: Instead of writing one large function to measure the square footage of a particular building, going through and adding the square feet of every room in the building for a given number of rooms - You could instead write a function to determine the square footage based on the result of a separate function used to calculate a room. This way your BuildingSquareFeet() function has just been transformed from a function for a specific building to a function that can be used on any building.

Duki 552 Nearly a Posting Virtuoso

I would also suggest sticking with arrays for now, especially since you have a set index. Something like this might get you going:

int num = 0;
string ary[25] = {"One", "Two", "Three", ... , "Twenty-Five"};

cout << "Give me a number:  " << flush ;
cin >> num;

for (int i = 0 ; ... ; ...)
    cout << num << " - " << ary[...] << endl ;

I've left blanks for you to fill in.

Fbody commented: I like the blanks... +2
Duki 552 Nearly a Posting Virtuoso

If that's all you need, then you could probably just use a tmp variable and a static count variable. If you just want the lowest number of guess for every round (i.e., if the fewest guesses it took for any given 10 rounds was 4 guesses, you want to output that) then just pass in a tmp variable, compare it to lowest_count, if lower, replace.

Duki 552 Nearly a Posting Virtuoso

@embooglement: Unless the o/p has an application that requires this type of encapsulation or abstraction - in which case, simply calling from main() won't work.

@o/p: I wouldn't avoid this type of design for the sake of preserving your stack, assuming it's because you're trying to maintain OOD. You'll see as you begin in a real-work environment, this is extremely common with larger applications. I work with software that sometimes has nested well over 10 functions before returning up the stack. If it helps you maintain a good design, and it's not a ridiculous number of function calls, don't worry about it.

Another point worth noting is the number of allowed function calls depends on the function and it's variables. Larger functions with large numbers of variables will decrease your stack much quicker than a simple 4-5 line method.

Duki 552 Nearly a Posting Virtuoso

Another thought is to use a static 2d array. e.g., [generated_num][count]

Duki 552 Nearly a Posting Virtuoso

You could save the values to a file each time. Then use a function to read those values, and determine the Count you want to display.

Duki 552 Nearly a Posting Virtuoso

Just use a break and loop like Fbody suggested.

e.g.,

int answer = 1;
while (answer >= 1 && <= 4)
{
	switch (answer)
	{
		case 1:
		{
			cout << "what do you want to do?\n";
			cin << answer;
			break;
		}
		case 2:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
		case 3:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
		case 4:
		{
			//do stuff
			
			cout << "what do you want to do now?\n";
			cin << answer;
			break;
		}
	}
}
Duki 552 Nearly a Posting Virtuoso

Maybe try something along the lines of

if (num % 10 == 0)
    cout << "0" ;

//reverse number code
Duki 552 Nearly a Posting Virtuoso

I'm sorry, I don't have an answer to your question...

I did literally "lol" at this though... :D

"http://127.0.0.1/gimmemore.mp3"

Good luck!

Duki 552 Nearly a Posting Virtuoso

Take a look here. Let me know if you have any questions. After you do the UPDATE command, you'll need to call your Fill() method again, to repopulate the grid showing only the items that have 'something'=true

Duki 552 Nearly a Posting Virtuoso

Ok, add something along the lines of SELECT * FROM table1 WHERE something=true

Then, when you click the button on your form, you can set 'something' = false in your database. Have you been able to connect to your database and update it? Or are you only using datagrids to read from it, and have done no writing?

Duki 552 Nearly a Posting Virtuoso
Duki 552 Nearly a Posting Virtuoso

How are you filling the data grid? Are you doing a SELECT * or some other query?

Duki 552 Nearly a Posting Virtuoso

I just tried calling, and the phone number isn't working anyways so no worries! :)

nick.crane commented: Made me laugh! +1
Lusiphur commented: Dude, no fair, I can't stop giggling now!! +1
Duki 552 Nearly a Posting Virtuoso

Yeah - that's what ShowDialog(); does. Have you tried it? If you don't trust me (and everyone else), do

this.enabled = false;

if it makes you feel any better.

Look here.

Duki 552 Nearly a Posting Virtuoso

More specifically, this post.

Duki 552 Nearly a Posting Virtuoso

Have a look at this thread. That should help.

............

Duki 552 Nearly a Posting Virtuoso

> You could write an Object Oriented Program (of course :P) that represents a 'virtual computer', you'll have to make classes for the processor, the motherboard, the graphical card, the ports (USB, FireWire, Serial, PS/2, etc.), the CD-Drive(s)...

Oooh I like that one, That sounds fun.

Duki 552 Nearly a Posting Virtuoso

Best C++ book I've ever used: C++ Programming: From problem analysis to problem design... by Malik.

Latest Edition

Duki 552 Nearly a Posting Virtuoso

One of my favorite projects I worked on was a small RPG type game.

I can't remember it all, but I had classes that were derived from base classes.. these were the fighters. Elvaan, Hume, etc. And each class had different traits... (Elvaan might have attack +10%, Hume might have a +10% chance of blocking, something else might have a +5% chance of attacking twice, etc.). Each race had different starting attributes, attack, strength, magic attack, HP, etc.

Then I put them all into a main() file for the fighting simulation. Each round would start a battle between 2 races. Main() would call the battle() function, which would setup the possibilities and call a random() function multiple times to determine who would attack, how much they would attack for and if anyone had the chance of blocking how often, etc. This would continue to loop, requiring the user hit Enter between every round, until one of the creatures was defeated.

Of coarse it took multiple runs to figure out if I had made one race too powerful or one race not powerful enough, which I then went back and made adjustments to the attributes.

Needless to say, this was an extremely fun exercise. Allows for a ton of creativity. :)

Duki 552 Nearly a Posting Virtuoso

Glad everything is starting to smooth over. I definitely understand the frustration of inheriting someone else's incompetence :)

If it were me (and I don't know your full situation) I would disable DCHP on anything and everything (including the wireless stuff) and run DHCP solely from your server.

What are the specs of your current server, and what all functions does it perform?

Duki 552 Nearly a Posting Virtuoso

It's strange that the MAC lead you to two devices, since they're supposed to be unique. Do you have any wireless gateways (linksys, netgear, etc.) that could have a DHCP service running on it?

Duki 552 Nearly a Posting Virtuoso

Just making sure, you're operating under a domain right? Is the DHCP server located on your domain controller?

Duki 552 Nearly a Posting Virtuoso

Take a look at this.

That explains it better than I can.

Duki 552 Nearly a Posting Virtuoso

can you post your updated code so that I know we're on the same page?

Duki 552 Nearly a Posting Virtuoso

No problem :)
1) Make sure the while loop is around the entire program... ending right before return 0 ; This way you can do "Try again? (y/n): " and you can change the if statement to if (letter == 'n' || letter =='N') THEN done = true ;

So your while loop should still be while(!done). Does that make sense?

I'm doing hw of my own right now, so I'm still looking at the rest of your program as I get time. I'll post back in a few minutes. Until then, do some desk checking (essential to every program you ever write).. get out a piece of paper and write down step by step what happens.

Duki 552 Nearly a Posting Virtuoso

You could change your while condition to while(done) instead of while(!done)... however you then have the problem of when the user gets to the end of the program, it doesn't re-execute the instructions() function.

Why don't you try putting a while loop around the entire program, take out the option to end the program from the instructions() function, and add the option right before the loop ends. Something like this:

Mostly pseudo code:

while(not done)
{
switch instructions()
    case 1:  manual() ;
break ;
    case 2:  file() ;
break ;
.
.
.
hangman game
.
.
.
cout << "Try again? (y/n):  " << flush ;
cin >> ans ;
if (ans == 'y' || ans == 'Y')
   done= true ;
else
   done = false ;
}//end while
cout << "-- Program Complete  --" << endl ;
Duki 552 Nearly a Posting Virtuoso

\\mistake

Duki 552 Nearly a Posting Virtuoso

I see a couple of things right off, but I haven't had time to get through the whole program.

1) You're not exiting your while loop until they select Done. Your condition is while(!done).

2) Your manual program should return the string that is input, shouldn't it?