Beginner Troubleshooting Help

My plan was to make a random generator for a d20 roll and to "x" number of rolls whilst adding each roll to a vector. Then I wanted to make a standard deviation function that would output the standard deviation of the rolls stored in the passed vector. I keep getting build errors and I can't figure out why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <vector>
using namespace std;


float stdDev(vector<int> list){
	//find the mean
	int sum=0;
	float mean=0;
	for(int n=0; n < list.size(); n++){
		sum += list[n];
	}
	mean = sum/(list.size());
	cout << "The mean value of the rolls is: " << mean << endl;

	//find the standard deviation
	vector<float> variances;
	float varianceSum=0;
	for(int i=0; i < list.size(); i++){
		float deviation = pow((list[i]-mean),2);
		variances.push_back(deviation);
	}
	for(int n=0; n < variances.size(); n++){
		varianceSum += variances[n];
	}
	double stdSqr = (varianceSum)/(list.size());
	double STD = sqrt((varianceSum)/(list.size()));
	cout << "The standard deviation of the rolls is: " << STD << endl;
	
	

	return 0;
}


int _tmain(int argc, _TCHAR* argv[])
{
	srand(static_cast<unsigned int>(time(0)));
	cout << "How many times would you like to roll the 1d20?" << endl;
	int rollNum;
	vector<int> ROLLS;
	cin >> rollNum;
	for(int i=0; i<=rollNum; i++){
		int randomNum = rand();
		int roll = (randomNum %20) +1;
		ROLLS.push_back(roll);
		cout << "Roll #" << i << " is: " << roll << endl;
	}

	stdDev(ROLLS);

	system("pause");
	return 0;
}

closed account (3hM2Nwbp)
During a quick read-through, I didn't spot any syntax errors, but then again, IANAC (I am not a compiler).

Could you post the compiler and/or linker output?
if by the output you meant the following, then sure:
1
2
3
4
5
6
7
8
1
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014: The build stopped unexpectedly because of an internal failure.
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014: Microsoft.Build.Exceptions.BuildAbortedException: Build was canceled. MSBuild.exe could not be launched as a child node as it could not be found at the location "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe". If necessary, specify the correct location in the BuildParameters, or with the MSBUILD_EXE_PATH environment variable.
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014:    at Microsoft.Build.BackEnd.NodeManager.AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration)
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014:    at Microsoft.Build.BackEnd.NodeManager.CreateNode(NodeConfiguration configuration, NodeAffinity nodeAffinity)
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014:    at Microsoft.Build.Execution.BuildManager.PerformSchedulingActions(IEnumerable`1 responses)
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014:    at Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node, BuildRequestBlocker blocker)
1>c:\Users\Owner\documents\visual studio 2010\Projects\dice roller\dice roller\dice roller.vcxproj : error MSB4014:    at Microsoft.Build.Execution.BuildManager.IssueRequestToScheduler(BuildSubmission submission, Boolean allowMainThreadBuild, BuildRequestBlocker blocker)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


(sorry for killing the frame)
Last edited on
Ran it on my Mac and it worked. Just changed the _tmain to main and got rid of the windows header.
1
2
3
4
5
6
7
8
9
10
$ ./a.out 
How many times would you like to roll the 1d20?
4
Roll #0 is: 12
Roll #1 is: 18
Roll #2 is: 12
Roll #3 is: 6
Roll #4 is: 3
The mean value of the rolls is: 10
The standard deviation of the rolls is: 5.2345
Thats exactly what I want it to output. So change that int _tmain(...){ } to int main()
{ }
?

And what is the windows header?
Just made two changes. Again I am on a MAC. You are also getting one more roll than I think you want. I wanted 4 rolls and got 5. That is because a <= what should be <

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//-----------------------------------
// Removed this
//#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <vector>
using namespace std;


float stdDev(vector<int> list){
        //find the mean
        int sum=0;
        float mean=0;
        for(int n=0; n < list.size(); n++){
                sum += list[n];
        }
        mean = sum/(list.size());
        cout << "The mean value of the rolls is: " << mean << endl;

        //find the standard deviation
        vector<float> variances;
        float varianceSum=0;
        for(int i=0; i < list.size(); i++){
                float deviation = pow((list[i]-mean),2);
                variances.push_back(deviation);
        }
        for(int n=0; n < variances.size(); n++){
                varianceSum += variances[n];
        }
        double stdSqr = (varianceSum)/(list.size());
        double STD = sqrt((varianceSum)/(list.size()));
        cout << "The standard deviation of the rolls is: " << STD << endl;



        return 0;
}

//----------------------------------------------------
// Changed from
//      int _tmain(int argc, _TCHAR* argv[])
// to
int main(int argc, char** argv)
{
        srand(static_cast<unsigned int>(time(0)));
        cout << "How many times would you like to roll the 1d20?" << endl;
        int rollNum;
        vector<int> ROLLS;
        cin >> rollNum;
        for(int i=0; i<=rollNum; i++){
                int randomNum = rand();
                int roll = (randomNum %20) +1;
                ROLLS.push_back(roll);
                cout << "Roll #" << i << " is: " << roll << endl;
        }
        stdDev(ROLLS);

        return 0;
}

Last edited on
Okay, I kept the windows header and changed the main function to how you had it. What does all of the int main(int argc, char** argv) part mean?
It is just how Linux/Mac wants the main entry point of the program to be called.
Oh okay, well thank you very much for taking a look at it. It works now and I just tweaked the mean finding code to be a float divided by a float--not an int / float.

It works!
Topic archived. No new replies allowed.