Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,395 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,132 people online right now. Registration is fast and FREE... Join Now!




What am I doing wrong now, window won't stay open

 
Reply to this topicStart new topic

What am I doing wrong now, window won't stay open

eadams20
24 Sep, 2006 - 07:27 AM
Post #1

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
Here is my code
CODE

#include <iostream> //access cout
#include <cmath>   // access power functions
#include <iomanip> // access fixed and setprecision

using namespace std;

int main()
{    
    int number1, number2, number3, number4;
    float mean;
    float standardDeviation;
    const float N = 4.0;
    
    
    //put output for formatting
    cout << fixed << setprecision(2);

    //input the four numbers
    cout << "Input the 1st number: ";
    cin >> number1;
    
    cout << "Input the 2nd number: ";
    cin >> number2;
    
    cout << "Input the 3rd number: ";
    cin >> number3;
    
    cout << "Input the 4th number: ";
    cin >> number4;

    //calculate the mean and output the mean
     mean = ((number1 + number2 + number3 + number4)/N);
     cout << "The mean of these numbers is: " <<  mean << endl;
    
     cout << endl;

    //calculate standard deviation and output standard deviation
    standardDeviation = sqrt((pow(number1-mean,2) + pow(number2-mean,2) +
                              pow(number3-mean,2) + pow(number4-mean,2)/ (N-1);
    cout << "The standard deviation is: " << standardDeviation << endl;
    
    cout << endl;
  
    cin.get(); //type enter to end
    cin.get(); //type enter to end

}


I tried using the .get twice, but still now luck, it pops up and off, I tried the pause and the get ch one but no luck. I have no idea if my code is even correct.

edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

Xing
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 08:22 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Check out for missing ) before ; in standard deviation calculation.

This post has been edited by Xing: 24 Sep, 2006 - 08:24 AM
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 08:32 AM
Post #3

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
Take off the cin.get(); at the end and add
CODE
system("PAUSE");
return 0;


You need to add the #include <stdlib.h>
at the beginning though.
User is offlineProfile CardPM
+Quote Post

eadams20
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 08:57 AM
Post #4

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
thanks sooo much! Got it to work

QUOTE(DeeViLiSh @ 24 Sep, 2006 - 09:32 AM) *

Take off the cin.get(); at the end and add
CODE
system("PAUSE");
return 0;


You need to add the #include <stdlib.h>
at the beginning though.

User is offlineProfile CardPM
+Quote Post

Mrafcho001
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 09:52 AM
Post #5

D.I.C Addict
Group Icon

Joined: 1 Nov, 2005
Posts: 753



Thanked: 5 times
Dream Kudos: 120
My Contributions
People have not implemented the Search feature for nothing...

http://forums.dreamincode.net/index.php?sh...c=16342&hl=
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 12:05 PM
Post #6

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
QUOTE(eadams20 @ 24 Sep, 2006 - 12:57 PM) *

thanks sooo much! Got it to work

QUOTE(DeeViLiSh @ 24 Sep, 2006 - 09:32 AM) *

Take off the cin.get(); at the end and add
CODE
system("PAUSE");
return 0;


You need to add the #include <stdlib.h>
at the beginning though.


It should be noted that the method described above is platform dependant, and is not ANSI standard.
User is offlineProfile CardPM
+Quote Post

Xing
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 05:24 PM
Post #7

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
QUOTE(DeeViLiSh @ 24 Sep, 2006 - 10:02 PM) *

Take off the cin.get(); at the end and add
CODE
system("PAUSE");
return 0;


You need to add the #include <stdlib.h>
at the beginning though.

Here's a portable and a standard conforming solution
CODE

#include <iostream>
#include <limits>

int main()
{
  
  // Rest of the code    
  
  //Clean the stream and ask for input
  std::cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n' );
  std::cin.get();
}

User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 06:50 PM
Post #8

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,013



Thanked: 18 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
very nice Xing!! it is always important to be universal in your code biggrin.gif
User is offlineProfile CardPM
+Quote Post

eadams20
RE: What Am I Doing Wrong Now, Window Won't Stay Open
24 Sep, 2006 - 07:50 PM
Post #9

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
Thanks for the link. I did however, read the tutorials on the subject and nothing helped my problem, but no matter, when I used a diffrent compiler I got it.

Emily

QUOTE(Mrafcho001 @ 24 Sep, 2006 - 10:52 AM) *

People have not implemented the Search feature for nothing...

http://forums.dreamincode.net/index.php?sh...c=16342&hl=

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:47AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month