User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,501 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,671 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 839 | Replies: 10 | Solved
Reply
Join Date: Jun 2007
Location: Home
Posts: 2,451
Reputation: zandiago is on a distinguished road 
Rep Power: 6
Solved Threads: 24
Featured Poster
zandiago's Avatar
zandiago zandiago is offline Offline
Nearly a Posting Maven

Troubleshooting Re: calculations with random #'s

  #11  
Sep 28th, 2007
 #include <cstring>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>

using namespace std;


int main()
{
	    

	double standardDev(int, int, int);
	
	srand ( static_cast<unsigned int> ( time ( 0 ) ) );
    int i,j;
    int Low = 147;    
    int High = 206;
    int numbers = 0;//the actual numbers
    
    double avg = 0.0;//average of group of numbers

    
    

    int count = 0;
    int sum = 0;
    int sumsquared = 0; 


	for (i=147; i < 207; i++)
    {
        count += 1;
        numbers = rand() % (High - Low + 1)+ Low;
		if (i%5==0)
		
			cout << numbers << endl;
		

        sum += numbers;
        sumsquared += (numbers * numbers);
    }
	
	for (i=0;i<count-1;i++)
	{
	for (j=i+1;j>count; j++)

	if (count>numbers)
	swap (count,numbers);
	}

    if (count > 0) 
	{
        avg = ((double) sum / (double) count);
        cout << "\n\nCount is: " << count << endl;
        printf("Average is: %.2f\n", avg);
        printf("Deviation is: %.3f\n\n", standardDev(sum, sumsquared, count));
    }

    return 0;
}

	// Function for calculating standard deviation
	double standardDev(int sum, int sumsquared, int count) {
    double deviation = (double) (sumsquared - ((sum * sum) / count));
    deviation = deviation / (double) (count - 1);
    double stndDev = sqrt(deviation);
    return stndDev;


		
		return 0;
} 
I made a bit of adjustments...regardless of what I put...it still shows a count of 60..though it only prints 10 numbers. Actually the count of numbers was suppose to be between 93 and 139 #'s whose range is between 147 and 206.
Thx for any assistance.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC