# why won't this work

This is a discussion on why won't this work within the C++ Programming forums, part of the General Programming Boards category; Code: # include <iostream> # include <cmath> using namespace std; int average, sd, s1, s2, s3, s4, deviation; int main() ...

1. ## why won't this work

Code:
```# include <iostream>
# include <cmath>
using namespace std;

int average, sd, s1, s2, s3, s4, deviation;

int main()
{
cout << "Press enter after entering a value.\n";
cout << endl;
cout << "Enter score one: ";
cin >> s1;
cout << "\nEnter score two: ";
cin >> s2;
cout << "\nEnter score three: ";
cin >> s3;
cout << "\nEnter score four: ";
cin >> s4;
cout << "\nThe average of your four scores is "<<average<<".\n";
cout << "The stand deviation of your scores is "<<sd<<".\n";

average =(s1+s2+s3+s4)/4;
deviation =(((s1-average)*
(s1-average))+((s2-average)*
(s2-average))+((s3-average)*
(s3-average))+((s4-average)*
(s4-average)))/3;
sd = sqrt(deviation);

return 0;
}```
&#91;code]&#91;/code]tagged by Salem

2. Here.... look at the difference, and think about it, I think you'll figure it out
Code:
```# include <iostream>
# include <cmath>
using namespace std;

int average, sd, s1, s2, s3, s4, deviation;

int main()
{
cout << "Press enter after entering a value.\n";
cout << endl;
cout << "Enter score one: ";
cin >> s1;
cout << "\nEnter score two: ";
cin >> s2;
cout << "\nEnter score three: ";
cin >> s3;
cout << "\nEnter score four: ";
cin >> s4;

average =(s1+s2+s3+s4)/4;
deviation =(((s1-average)*(s1-average))+((s2-average)*(s2-average))+((s3-average)*(s3-average))+((s4-average)*(s4-average)))/3;
sd = sqrt(deviation);

cout << "\nThe average of your four scores is "<<average<<".\n";
cout << "The stand deviation of your scores is "<<sd<<".\n";

return 0;
}```

3. You are outputting the values before you are computing them for one. Second, you probably want to use doubles for the average and standard deviation (if not all the inputs as well) so they can have decimals.

4. lol, look at his code again Inquirer.... see the error?

Oh, and yea... good idea SS

5. You can use cin to get pretty much every basic type (perhaps not bools).

6. BMJ:
so can you input integers thru cin? *is confused* i never thought you could.........

~Inquirer

7. sure.. you can do this:
Code:
```int x;
std::cin >> x;```
And if they enter an integer, it will be stored as x... if they do not enter an integer.... heh, well you'll have a problem.

8. hehe. I didn't even look that far. But, i learned something today. thanks.

~Inquirer

9. You should use atoi() when getting integer input with cin

10. ## Thanks you guys

Thank you very much, I understand what i did wrong

11. I knew you could figure it out

12. ## new problem

How do i get this code to loop infinitely until the user tells it to stop?

# include <iostream>
# include <cmath>
using namespace std;

double average, sd, s1, s2, s3, s4, deviation;

int main()
{
cout << "Press enter after entering a value.\n";
cout << endl;
cout << "Enter score one: ";
cin >> s1;
cout << "\nEnter score two: ";
cin >> s2;
cout << "\nEnter score three: ";
cin >> s3;
cout << "\nEnter score four: ";
cin >> s4;

average =(s1+s2+s3+s4)/4;
deviation =(((s1-average)*(s1-average))+((s2-average)*(s2-average))+((s3-average)*(s3-average))+((s4-average)*(s4-average)))/3;
sd = sqrt(deviation);

cout << "\nThe average of your four scores is "<<average<<".\n";
cout << "The standard deviation of your scores is "<<sd<<".\n";

return 0;
}

13. What do you mean by loop? Do you want it to go through getting all the scores? Or do you want the use to be able to stop at any time by typing 'Q' or something?

14. what i mean is that i would like the user to be able to repeat the program. i would like the user to be able to input different scores each time. This would happen over and over again until the user wanted to stop. For instance,

average
mean

"would you like to run the program again? y or n"

then they would hit "y" as long as they wanted to use the program. when they want to quit, they would hit "n"

15. Hi,
I would really like to know how did you input integers without using cin?