jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So start by asking yourself what would 1 iteration look like, then 2, then 3. Find the commonalities and use your loop to automate the whole thing. In doing these types of computations generally 2 variables are used, one that holds the prior value, one that holds the next value and then the sum of those two gets assigned to the first one for the next iteration.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. I had edited my post a couple of times so I didn't know if you got the latest one. It's all good.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh ok. I meant to change it in the other two places but not in the function call itself. Take out the brackets on line 55 and just call it with students like you did before.

There's some work to be done in the function definition. You need to come up with a name for your parameter that is of type theStudent and use that in the function instead of just theStudent. You also can't test for equality between a struct and a value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post up the search function too so I can give it a try?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It probably means you should move your prototype after your struct (probably the best idea) or you can forward declare your struct (put "struct theStudent;" before your prototype and leave the struct declaration in place).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your first argument in the search function should be prototyped as theStudent [] instead of int [] (and probably needs to be changed in your function definition as well.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For your ratio try 364.0/365.0, you probably keep getting 0 for 364/365 since it's still considered integer division.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Got it, I think.

See if this is what you need. I left the System:: etc. qualifiers on there just to make sure it wasn't getting the wrong classes. I'm pretty sure everything you need is there, but if need be I can upload the project.

valeriy_zf commented: Good job, Thank you! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

string.str(a) So you're still not doing anything with that statement. You have almost everything you need, but treat your string like an array a[0] is the first character a[a.length() - 1] is the last.

Also, how are your results getting back to main? Look up what it means to pass something by reference. You have it the right way in your method, just not in main.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, I've got to puzzle over it some more. I think we've got it there's just a simple scope issue that I'm running into.

Well, you could break up the drawing procedures again and give the form access to them (might be easier). Anyway, best of luck with it. Apologies that I couldn't help more.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This works too #include <iomanip> cout << " The mean is: " <<fixed<<setprecision(2)<< mean << endl; . It doesn't have to be in the statement itself, it can be beforehand.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just looking over your code again, I'm realizing that you are trying to make a form within your Test1 class. I would make it separate and have it include your Form1.h as a header and use the namespace from your Form1.h file (and your project overall).

#include "Form1.h"
using namespace FormControlinClass;

Then include your Test1.h file in your form1.h file (there's a way to take care of all of this with stdafx.h but I'm not up on it enough).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm having difficulty with it after I tried it out. I will figure it out. Part of the problem (unrelated to the one that we are having now) is that the button is declared as private within the Form1 class. In order to access it it needs to be public.

EDIT: What you have up there is not correct. You should be instantiating Test1 in the form header, not making a new form1 there. You don't need to start another form in form1 you have one. Test1 ^ mytest1 = gcnew Test1(this); pass in the pointer for the form from the form class.
Then in the click method put mytest1->ChangeButtonText();

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No problem. Good luck!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This would be the constructor for the same class that contains your Change_Button_Text() -- sorry I missed the underscores when I wrote it out. So when you instantiate Test1 in form1.h you just pass in "this" to the constructor. Make sure you put the new prototype for the constructor in your header as well.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C++ won't help you really at all with web stuff (though there are some technologies like this which allow users to run C code in the browser). C# (which is related to C++) can be used in ASP.NET coding on the web.

In terms of tutorials for HTML and Javascript (which is a smidge like C++ actually) I would pop over to the folks in the DaniWeb Web Development forums and see what they have for sticky threads over there. I'd imagine there are quite a few. I went through some of the w3schools material at one point and I found it pretty well laid out but definitely see what they recommend first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Search around on this site for "text based RPG." People early on in their programming seem to really enjoy creating though without using functions and the like they can get a little unwieldy. I know a user named Restrictment had posted the code for his some months back. It couldn't hurt just to look at it and see where he went with it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So lines 48 and 50 are still wrong. Strings do not have single quotes. I'm not sure what more I can tell ya.

totalwar235 commented: worked perfectly +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I first ran into Adatapost in the C# section. He was a fairly prominent figure there when I first started (all those long months ago!!) and still keeps up his posts as a mod. I think he's patient and kind to the extreme and truly enjoys helping people learn. He's also encouraging with rep and nice comments!

P.S. Just like with vegaseat, I have yet to figure out what an adatapost is. Is that like a sign post for data to follow? ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post your latest code please. Did you make the changes in my last post with regards to double quotes where you had single quotes?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather than instantiating a new fr1 within your class, let the constructor of Test take your form as an argument:

In the declaration in the header:
private: Form1 ^ frm1inclass;
In the cpp file:
Test1::Test1(Form1^ form1)
{
     this->frm1inclass = form1;
}

void Test1::ChangeButtonText()
{
        frm1inclass->button1->Text = "Whatever here";
}

I didn't try compiling it so there may be some missed "punctuation" but you get the idea.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That finally ends countless hours of idle speculation on my part. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Vegaseat

So is it truly "Vegas Seat" or "[Chevy] Vega Seat" or "[star] Vega Seat" or "Vegas Eat"? There are a few others but I don't know him well enough to write them...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
char option[7]; //at the top
....
fgets (option, 7, stdin);
for (m = 0;m <sizeof(option);m++)
    if(option[m] == '\n')
    {
         option[m] = '\0';
	 break;
     }

What we overlooked is that fgets may take in a newline from when we hit enter. You need to have the above construct to get rid of it and put a '\0' (for null termination) in the right place. That way the longer string will be truncated to the same length as the one you are using for strcmp. See this for details.

You'll have to do this for all the strings you read in.

You still didn't change the flow of your program to be like:
"Enter a name:"
"Enter a number: "
"Do you want to enter more numbers?"
(which I think is the most logical way of doing it -- if you were running this program to use as an actual telephone directory you wouldn't want to remember which name you entered first, third etc.)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Super! I was going to suggest that at one point but I thought it was redundant. Oh well. Glad it worked out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've done it again WaltP! That's my bad. Well, Dave's thread's a good read anyway. :)

I still maintain that reading in character by character (and seemingly throwing them away once a new one is read) is probably not the best approach.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's best not to use EOF.

You probably don't have to read character by character also. Look into the >> operator and the getline() method of istream (implemented by ifstream).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You got me. It did seem like people were having problems sending from gmail. I only sent to gmail not from it.

By other settings I mean the members of SmtpClient.

I'm afraid I don't know much more than this about these types of systems.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Give me a tutorial

This is very demanding and bordering on rude.

Despite that I (more than wholeheartedly) agree with WaltP's sentiment I still wanted to plug a book that I really liked which was this. It's also legitimately free which is nice.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure what the problem is... I sent via ISP's SMTP server to gmail and it worked. A couple of possibilities I ran across:
Try changing client->Port to 587.
-or-
Make sure you're running as admin so that you have the right privileges to send email.

There may be a few other settings you can play with. You could try asking your ISP/server admin for details...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wow. I'm speechless and totally honored. I'll have to return the favor:

Nick Evan:
Well what can I say a great moderator and a great guy( when he's not running over elderly men on their bikes off the road for the sake of a good story).

When I first got here I thought he was a moderator because he kept a level head and kept discussions on track (he officially became one soon after that). Like all of the great mods here he offered excellent advice too! He has too many posts to count (well over 3k) and has (according to the rollover label) "a reputation beyond repute."

One thing I don't know is how to pronounce his screen name. I tend to pronounce it like Nicky, but I suppose it could rhyme with "sneaky" or sound like "Nikkei."

Well, there's so much more I could say but I'm sure there will be many others who will sing his praises.

(as a response to one of his comments: I'm very deliberate about my bad post reporting, I know. I also figure that the top secret moderator forum must get pretty boring so I do like to provide a little entertainment with my reports--occasionally it trickles out into my non-Geeks' Lounge posts as well)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It may seem silly but just say them out loud if you forget "greater than > or equal = to", >= and "less than < or equal = to", <=

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's only 3 lines:

System::IO::StreamWriter ^ sw = gcnew System::IO::StreamWriter("Outfile.txt");
sw->Write(textBox1->Text);
sw->Close();

you can use a "using namespace System::IO;" to cut down on the syntax

(speaking of which there's a different context of the "using" keyword in .NET where if you wrap your readers/writers/( anything that need to be "dispose"d of properly) in one it takes care of everything including closing but I'm not sure if it functions the same in C++/CLI as it does in C# -- this snippet should do the job just fine)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try substituting these in for line 8. You were trying to pass it into client as static which might work but this way you get all the proper info in there. I tested it, it works.

CredentialCache ^ mycreds = gcnew CredentialCache();
	mycreds->DefaultNetworkCredentials->UserName = "bob";
	mycreds->DefaultNetworkCredentials->Password = "bob";
	
	client->Credentials = mycreds;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can look into turning String^ into std::string but it's a hassle to keep moving the data back and forth (juggling the pointers and shifting them between managed and unmanaged). You hit the nail on the head in your first post in that it really is a new language unto itself.

My best suggestion (and others may have better ones) is if you want to keep your existing code base to look into MFC (if you have the standard or higher edition of VS, it's not in the express) or Win32API (which is in the standard and express but takes more code to cover the basic windowing).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That ignores up to 80 characters in the input stream until it finds a '\n' (so if it finds the newline, the '\n' is ignored and it stops).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

have a program that pops up and has buttons to run different code i made

Unless you've got some GUI experience in another language that's going to be a bit of a road...give it time.

i want to make it so its kind of a game where i have the questions and depending on the score at the end they either have to redo the questions or go to a new set...

That's going to take some strings knowledge. Grab some tutorials. Start simple. Look into arrays to store your questions. Look into files to store additional sets of questions.

correct == >3
correct ==<3

See if you can figure out what's wrong with those two statements.

Agni commented: You've got patience, you can make an excellent teacher :) .. +3
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for (j = 0; j < 10 && strcmp (choice,"yes") != 0; j++) This is part of the problem, it should be strcmp == 0 as when the condition of the for loop goes false the loop stops.

It still is skipping over those fgets. I'm looking into that.

In the meantime you should look into rearranging things a bit so you're taking a name, then taking a number, that way the name and number arrays line up. Otherwise you are asking the user to enter 10 names and THEN enter 10 numbers.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can declare and initialize on the same line:

int correct = 0;
int total = 0;

As far as your "assignment" I say let creativity be your guide and look up features of the language you think you need. Try to also follow something like a tutorial or a book to bring some structure to your studying.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

str() is a method used with stringstreams to get the string portion. It doesn't seem like you need stringstreams or str() here.

Remember that you can access strings as an array, so string[0] is the first character of the string. string.str(s) <= s doesn't make any sense. You were on to something when you were talking about the length() method. So you know how long the string is once you've read it in.

If you are calling your method in main, you need to pass in all of the parameters including the reference ones.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The name of my text box is txtbox.

Apologies it was worth a shot.

I think you need to have txtbox->Text.

It's that and you need to convert the String^ to a std::string. It might be a rough road. I know the .NET stuff from the C# side so forgive my difficulties with integrating managed and unmanaged stuff.

EDIT: I would look up how to use System::IO::StreamWriter as I I think it will make life a lot easier. It avoids all of the moving pointers from managed to unmanaged and the syntax is pretty straightforward.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You would need to write the event handlers themselves ahead of time, so you couldn't have the user pick their own once the control was created.
So here's a normal event handler "hookup":

this->panel1->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::panel1_MouseDown);

In your case you'd be creating "panel1" dynamically and so you'd already have to have premade_MouseDown() written out instead of panel1_MouseDown. So you'd have a statement like the above after you've created your object where you're hooking up your method to the control.

That's probably as clear as mud. You just have to do in code what the Winforms does for you when you double click on an event in the properties.

Do some searching for this topic under ASP.NET sites (or even in the ASP.NET forum here :) ) as I think this is more common occurrence in that domain.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can get which button was pressed via the e->Button member of the MouseEventArgs object. I don't know your design (sounds scary with all those controls lol) so I'm not sure what the button43 has to do with it, but you can get a MouseEventArgs in the button43_MouseDown if you need it.
I'm not sure what's causing the phenomenon that you are observing but perhaps if you are clicking again before everything is set your string is reflecting the old value(?).
If you really need information to pass from event handler to event handler then you can inherit from the MouseEventArgs and add what you need to it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is the name of your textbox? Identifiers like that are case sensitive so if it's "Textbox" or "textBox" (more likely the latter) it's not going to work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if ( green == 1 || green == 1.) There is no such thing as 1. with an integer. Just use if (green == 1) For keeping track, make another integer variable called correct and one called total or something like that. Set them both to 0 when you declare them (so int correct = 0; ).

if(green == 1)
{
       cout<<"Correct"<<endl;
       correct++;   //shorthand for correct = correct + 1;
} //need the braces for multiple statements under one if

else
      cout <<"Wrong"<<endl;

total++;  //after both if and else are done

cout <<"You have "<<correct<<"/"<<total<<endl;

if(yellow == 3)
{
     cout <<"Correct"<<endl;
     correct++;    //don't redeclare it or set it to 0 again
}
else
      cout<<"Wrong"<<endl;

total++;


cout <<"You have "<<correct<<"/"<<total<<endl;

Repeat that for as many as you want.

You're starting to get it ok. Keep reinforcing what you are learning but don't be afraid to delve further into the language so you can expand your repertoire.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You get where the click came from via the e parameter. e->X gives you the x coordinate and e->Y the y. It's going to be tricky to get your user to grab the exact point I think, you may want to use a (small) range.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

on line 13:

gets(initial);

Please don't encourage anyone to use gets. It has no restrictions to the size of input so it can clobber the adjacent memory causing a disaster. See this by WaltP.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is a frustrating thing to deal with. I looked at it as such:
Make a class that holds your data points in a list and has a member method Draw, drawing each point up until time.

void Points::Draw(Graphics^ g , int time)
	{				
			Pen ^ mypen = gcnew Pen(Color::Black);
		for(int i = 0;i<time;i++)
			g->DrawRectangle(mypen,listpts[i].X,listpts[i].Y,1,1);
	}

In form1.h have 2 event handlers

private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
				 pts->Draw(e->Graphics,time);
				 time++;
				 
				 }
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
				 Invalidate();
				 }

Use an interval on the timer of 1000 and start it in the Form1 constructor. Each time the timer ticks (1 sec) it will paint all of the dots up until that time. I'm sure there's a better way to do it but there may be no escaping the need to repaint all of them on each new dot.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oops, didn't think about putting that after the comma. I'm on a roll today.

WaltP commented: Hey, sometimes it's better to just go to bed :D +9