|
My alternative handles this case.
You could place an 'if ' around each prompt, something like this:
if (N >= 3) {
cout << "Enter score 3 ";
cin >> score3;
}
if (N >= 4) {
cout << "Enter score 4 ";
cin >> score4;
} Doing that, you only prompt for and read in the number of scores that you need.
Software Zen: delete this;
|
|
|
|
|
First use double not float. Second lose the (float) cast: the fact that a C-style cast is used at all in a C++ program is bad enough (not everyone agrees with this; the ones that don’t are wrong!) but score1 is already a float anyway.
Steve
|
|
|
|
|
Can you provide with a sample input data and expected mean and variance. I can't see anything wrong in the code. Only thing I can think of is you are computing biased variance in the code but true answer with which you are comparing with might be un-biased variance. See here[^] for more information about variance.
-Saurabh
|
|
|
|
|
Hi, I really appreciate your help here. The variance is worked out like the first example that you redirected my browser to regarding variance (the website about it). Example: Numberofscores(N)=2, score1=2, score2=5, all the other scores are input as 0 (seeing there is no scores). The mean is worked out as 2 + 5 / 2 = 3.5 (the program will do this calculation). Variance is worked out like this: (score1 - Mean) to the power of 2 + (score2 - Mean) to the power of 2 / 2 (N). I did not know what power was in C++ so I times it by itself. I think maybe there is something wrong with the compiler I am using as it will not recognise some commands. It does not return any errors but the calculations are wrong for the variance.
Here is my code:
#include <iostream>
using namespace std;
int main(void)
{
double M, N, total, score1, score2, score3, score4, score5, score6, score7, score8, V1, V2, V3, V4, V5, V6, V7, V8, s1, s2, s3, s4, s5, s6, s7, s8;
cout << "Input the number of people in sample ";
cin >> N;
cout << "input the 1st score ";
cin >> score1;
cout << "input the 2nd score ";
cin >> score2;
cout << "input the 3rd score ";
cin >> score3;
cout << "input the 4th score ";
cin >> score4;
cout << "input the 5th score ";
cin >> score5;
cout << "input the 6th score ";
cin >> score6;
cout << "input the 7th score ";
cin >> score7;
cout << "input the 8th score ";
cin >> score8;
total = score1 + score2 + score3 + score4 + score5 + score6 + score7 + score8;
M = total / N;
cout << "the mean for these scores is: " << M << "\n";
s1 = score1 - M;
V1 = s1 * s1;
s2 = score2 - M;
V2 = s2 * s2;
s3 = score3 - M;
V3 = s3 * s3;
s4 = score4 - M;
V4 = s4 * s4;
s5 = score5 - M;
V5 = s5 * s5;
s6 = score6 - M;
V6 = s6 * s6;
s7 = score7 - M;
V7 = s7 * s7;
s8 = score8 - M;
V8 = s8 * s8;
cout << "the variance for these scores is: " << (double) (V1 + V2 + V3 + V4 + V5 + V6 + V7 + V8) / N << "\n";
return 0;
}
linda
|
|
|
|
|
Notice that if score3 to score8 is 0, the values for V3 to V8 is (0 - 3.5)^2 and you use these in your calculation for variance.
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
vector<double> scores;
double score;
double mean;
double total = 0;
double variance = 0;
int numberOfPeople;
cout << "Input the number of people in sample: ";
cin >> numberOfPeople;
for(int n = 0; n < numberOfPeople; n++)
{
cout << "Input the score for person " << n+1 << ": ";
cin >> score;
scores.push_back(score);
total += score;
}
mean = total / numberOfPeople;
cout << "The mean for these scores is: " << mean << "\n";
for(int n = 0; n < numberOfPeople; n++)
{
double temp = scores[n] - mean;
variance += temp * temp;
}
variance /= numberOfPeople;
cout << "The variance for these scores is: " << variance << "\n";
return 0;
}
|
|
|
|
|
Hi there
Thanks for that
I appreciate your code, it is good.
I think I need to study some more before attempting to write calculations like this
linda
|
|
|
|
|
Oh I got it now, your code is correct but you are using it incorrectly. You have written code for computing variance of 8 numbers but you are trying to use it for only two numbers. Let me explain.
Code for mean is M = (s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8) / N;
when you give N =2, s1 = 2, s2 = 5 and rest equal to zero.
mean becomes M = (s1 + s2 + 0 + 0 + 0 + 0 + 0 + 0) / N = (s1 + s2) = N
which is correct so mean is computed correctly.
Code for variance is [(s1-M)*(s2-M) + (s1-M)*(s2-M) + ... + (s8-M)*(s8-M)] / N. Now when you give N =2, s1 = 2, s2 = 5 and rest equal to zero. Variance becomes [(s1-M)*(s2-M) + (s1-M)*(s2-M) + (0-M)*(0-M) + ... + (0-M)*(0-M)] / N which is not what you want. Correct formula for variance of two numbers is [(s1-M)(s1-M) + (s2-M)(s2-M)]/2.
I hope this helps.
-Saurabh
|
|
|
|
|
invalid autondication specification message from server
"access denied for user root@ist3 (using password : YES)"
sql status 2800
error code 1045
how to set password for database in mysql 5.0
please tell me
its urgent
JAYARAJ
|
|
|
|
|
|
see the mysql's online manual (under the directory docs in the installation dir) and read the "post-installation setup and testing" section.
everything you need to know is available there. good luck
|
|
|
|
|
Hi,
Question 1:
-----------
The GetStdHandle() API is returning INVALID_HANDLE_VALUE.
When does this API returns INVALID_HANDLE_VALUE. When GetLastError is called it returns 6 (The handle is invalid).
Is there any condition in which this API return INVALID_HANDLE_VALUE.
Question 2:
-----------
With Reference to MSDN under the topic pipes/Anonymous Pipe/Pipe Handle Inheritance
The following are the steps mentioned for redirecting the standard output handle to the child process
1.Call the GetStdHandle function to get the current standard output handle
2.Call the SetStdHandle function to set the standard output handle to the write handle to the pipe.
3.Create the child process
4.Call the CloseHandle function to close the write handle to the pipe.
5.Call SetStdHandle to restore the original standard output handle
The Question is whether there will be any impact in the parent process when the restoring of the original handle is not done.
Thanks in advance.
|
|
|
|
|
maybe it is some helpful to you here[^]
whitesky
|
|
|
|
|
e_prabhu wrote: Is there any condition in which this API return INVALID_HANDLE_VALUE
Yes, if you don't provide a correct parameter, or if you are calling it from a GUI program, rather than a console program.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi,
In my project i am adding some name and i displayed in ListBox.I can add,edit and delete the name in listbox.Each time i updated my ListBox ny using one function
CTag::UpdateListBox()
{
CTagBase* Temp;
CListBox* mWnd = (CListBox*)GetDlgItem(IDC_LIST_POINT);
mWnd->ResetContent();
POSITION pos = goTagList.GetHeadPosition();
while(pos)
{
Temp = (CTagBase *) goTagList.GetAt(pos);
mWnd->AddString(Temp->GetTagInfo());
goTagList.GetNext(pos);
}
UpdateData(FALSE);
}
In GetTagInfo function
CString CTagAlrmLgt::GetTagInfo()
{
CString TempData;
char Temp[50];
TempData = TagName + (CString)"\t" + (CString) Description + (CString)"\t" + (CString)"\t";
return TempData;
}
This is iam doing in GetTagName.
And the ListBox is loaded with full details.But my problem is when i closed the dialog and when again i opened the dialog,the details are not correct and it shows some different characters.I dont know the reason.
I called UpdateListBox() function in OnInitDialog()
|
|
|
|
|
when you reopen your dialog are you sure that UpdateListBox is run
WhiteSky
|
|
|
|
|
Hi,
I am working on developing a media player which can run any format files like it can run .mov,.rm and all other formats which windows media player supports.How it can be done please help me
Anupam
|
|
|
|
|
Use DirectShow. You can have a look at the PlayWnd sample in the DirectShow SDK.
|
|
|
|
|
maybe it is some helpful to you
See mci functions
WhiteSky
|
|
|
|
|
WhiteSky wrote: See mci functions
ohh, MCI function can't support MP3,rm,ram format!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I wrote one program that use mci and i could open mp3
anyway i test now and i can play mp3
<br />
MCI_DGV_OPEN_PARMS mciOpen;<br />
<br />
mciOpen.dwCallback = 0L;<br />
mciOpen.wDeviceID = 0;<br />
mciOpen.lpstrDeviceType ="MPEGVIDEO"; mciOpen.lpstrElementName = ReturnString;<br />
mciOpen.lpstrAlias ="MPEGVIDEO"; mciOpen.dwStyle = WS_CHILD;<br />
mciOpen.hWndParent = hWnd;<br />
mciSendCommand(0, MCI_OPEN,<br />
MCI_OPEN_ELEMENT |MCI_OPEN_TYPE,<br />
(DWORD)(LPVOID) &mciOpen);<br />
...<br />
...<br />
whitesky
-- modified at 11:01 Saturday 13th May, 2006
|
|
|
|
|
WhiteSky wrote: I wrote one program that use mci and i could open mp3anyway i test now and i can play mp3
I havn't try that! could you send me the source code!.. but AFAIK, it doesn't support rm and ram format!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Sure
i dont know for rm or ram but for mp3 i know
of course i have this program but it has a little problem so i create(rewrite) this program form about
two hours ago and i send for you now.
whitesky
|
|
|
|
|
Hi friends,
we are trying to establish connection between vnc client and server vai stunnel and openssl.we perform all steps. reference for steps is given at following address
D:\Openssl\OpenSSl\Remote Desktop Management Solution for Microsoft.htm
according to steps,create certificates for vncclient and vncserevr for authentication. final o/p is not establish connection.
o/p comes is as follows in log file which is not correct
2006.05.13 15:38:09 LOG5[1804:1712]: stunnel 4.15 on x86-pc-mingw32-gnu with OpenSSL 0.9.7i 14 Oct 2005
2006.05.13 15:38:09 LOG5[1804:1712]: Threading:WIN32 SSL:ENGINE Sockets:SELECT,IPv6
2006.05.13 15:38:09 LOG5[1804:1976]: No limit detected for the number of clients
friend kindly give us reply about our problem.
regards
Girish
Software Developer
|
|
|
|
|
Hello everybody, I am about to create a database-oriented program for a Video Club.
I have in my disposal MFC, Delphi, VBA and I am going to use MySql for the Database.
I need any suggestions about which programm language to use.
I know that a program is much easily implemented with Delphi but I am a C++ fun.
Is it easy enough for a single person to create a decent program of this kind by
using MFC within a period of a few months?Have in mind that I am not a Guru.
|
|
|
|
|
Lord_Vader wrote: Is it easy enough for a single person to create a decent program of this kind by
using MFC within a period of a few months?Have in mind that I am not a Guru.
I am too great fan of VC++, but my suggestion would be create your project/software in the language you are comfortable with!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|