Page 2 of 3

Re: push_back, square( )ect.ect.

Posted: Wed Mar 25, 2009 2:17 pm
by Ginto8
kostiak2 wrote:

Code: Select all

for (unsigned int i=0;i<temps.size();++i)sum+= temps[i];
for my style, I changed some things:

Code: Select all

for(unsigned i = 0; i < temps.size(); ++i)
    sum += temps[i];
just pointing out that you can shorten "unsigned int" to "unsigned". I changed the style so my head wouldn't explode. ;) :lol:

Re: push_back, square( )ect.ect.

Posted: Wed Mar 25, 2009 4:09 pm
by kostiak2
I actualy prefer:

Code: Select all

for (unsigned int i=0;i<temps.size();++i)
{
    sum+= temps[i];
}
I just didn't want to bitch about it :lol:

Re: push_back, square( )ect.ect.

Posted: Wed Mar 25, 2009 5:53 pm
by K-Bal
Yeah and what happens if you type in

unsigned x = 0.5f; ? ;)

I guess, I'll try that out later.

Re: push_back, square( )ect.ect.

Posted: Thu Mar 26, 2009 7:14 am
by Ginto8
K-Bal wrote:Yeah and what happens if you type in

unsigned x = 0.5f; ? ;)

I guess, I'll try that out later.
The program will have to do a runtime conversion, making x = 0. ;)

Re: push_back, square( )ect.ect.

Posted: Thu Mar 26, 2009 8:15 am
by MarauderIIC
Actually, it doesn't return an unsigned int. It returns a size_type (vector::size_type, super-specifically). Which happens to be an unsigned int. But "it might not be later." The same way that NULL "might not be 0 later."

Also, I don't write size_type either, but I think your loop should (technically, again) look like this:

Code: Select all

for (vector::size_type i = 0;i < myVector.size();++i)
But... that's slow (you're recalculating the size every time!). So you shouldn't be doing that, anyway. You should at least be doing this:

Code: Select all

const unsigned int max = myVector.size();
for (unsigned int i = 0; i < max;++i)
But this is faster:

Code: Select all

for (vector<myVecType>::iterator i = myVector.begin(); i != myVector.end();++i)
Where myVector is defined as

Code: Select all

vector<myVecType> myVector;
And you can probably go even farther and (I don't go this far) :

Code: Select all

const vector<myVecType>::iterator max = myVector.end();
for (vector<myVecType>::iterator i = myVector.begin(); i != max; ++i)

Re: push_back, square( )ect.ect.

Posted: Fri Mar 27, 2009 8:57 pm
by cplusplusnoob
ok this does work and sorry again schools been loading on the homework and I have to make money now and then too so for the lateness my appologies.

Like I said earliar this does work but when all nubers are written in a box pops up with a big explination point and says debug assertion failed.

why?
ps.If it matters I am using microsft visual c++ express edition.

Re: push_back, square( )ect.ect.

Posted: Tue Mar 31, 2009 9:39 pm
by MarauderIIC
What line?

Re: push_back, square( )ect.ect.

Posted: Wed Apr 01, 2009 9:34 am
by MadPumpkin
you should change the post name if possible, because the abbreviation you're looking for it etc. NOT ect.
ect. makes it look like your trying to say eccetera, exetera, ecetera... but, the phrase Et Cetera, is what it should stand for, so etc. is correct. It is Latin it means "And So On(ward)"

:) thats all : D

Re: push_back, square( )ect.ect.

Posted: Wed Apr 01, 2009 7:47 pm
by cplusplusnoob
first off i will enter the data and it will say the average and median tempurature and then the debug asertion warning thing.
second thank you for cerrecting me im all for that. :)

Re: push_back, square( )ect.ect.

Posted: Wed Apr 01, 2009 8:48 pm
by MarauderIIC
Okay, so what comes after the median temperature line?

Re: push_back, square( )ect.ect.

Posted: Thu Apr 02, 2009 4:26 pm
by cplusplusnoob
I think nothing but, then again their might be some spaces in there.Anyway pretty much nothing comes after the median tempurature line other than the warning that pops up.

and thank you :)

Re: push_back, square( )ect.ect.

Posted: Fri Apr 03, 2009 12:36 am
by MarauderIIC
I meant code-wise.

Re: push_back, square( )ect.ect.

Posted: Fri Apr 03, 2009 4:30 pm
by cplusplusnoob
I am not sure if this is what you meant but it could be between line 19 and line 24. ;) :lol:

Re: push_back, square( )ect.ect.

Posted: Fri Apr 03, 2009 7:21 pm
by dandymcgee
cplusplusnoob wrote:I am not sure if this is what you meant but it could be between line 19 and line 24. ;) :lol:
Lmao.

Re: push_back, square( )ect.ect.

Posted: Fri Apr 03, 2009 10:03 pm
by MarauderIIC
It's like trying to pull teeth from a chicken.

Look, this is all the source of yours I found in this thread:

Code: Select all

using namespace std;
int main()
{
   vector<double>temps;
   double temp;
   while(cin>>temp)
      temp.push_back(temp);
   double sum=0;
   for (int i=0; i<temps.size();++i)sum+= temps[i];
   cout<<"average temurature: "<<sum/temps.size()<<endl;
   sort(temps.begin(),temps.end());
   cout<<"medean temurature: "<<temps[temps.size()/2]<<endl;
What comes after the last line here? It seems like there wouldn't be an error in this code.