Results 1 to 11 of 11
  1. #1
    Zombie's Avatar
    Join Date
    Nov 2013
    Gender
    male
    Location
    Clearwater, Florida
    Posts
    414
    Reputation
    52
    Thanks
    93
    My Mood
    Happy

    Super Simple Average Calculator

    As a few of you already know, I've started to get my feet wet in C++, and this is what I've got so far:

    Code:
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    int x;
    int y;
    
    int main()
    {
    	cout << "Let's calculate an average!" << endl << endl;			// Simple title, going to figure out colors next
    	
    	cout << "Input your first number: " << endl << endl;			// Asks for input, no actual search for an input
    	cin >> x;								// Grabs users input, stores it in x
    	cout << endl;								// Line skip to make it look pretty
    	cout << "Your first number is: " << x << endl << endl;			// Spits back x value, because why not
    
    	cout << "Input your second number: " << endl << endl;			// Asks for input, no actual search for an input
    	cin >> y;								// Grabs users input, stores it in y
    	cout << endl;								// Line skip to make it look pretty
    	cout << "Your second number is: " << y << endl << endl;			// Spits back y value, because why not
    
    	system("cls");								// Clear that shit
    
    	cout << "Your average is: " << (x + y) / 2 << endl << endl;		// Outputs the average, super simple.
    
            return 0;								// Ain't returnin' shit.
    }
    Quote Originally Posted by thepieceofshit View Post
    i have another hack

    come pm on mpgh

    u press f1 you get dick in ur butt

  2. #2
    -Panda-'s Avatar
    Join Date
    Nov 2012
    Gender
    male
    Location
    Australia
    Posts
    1,764
    Reputation
    42
    Thanks
    209
    My Mood
    Bored
    I thought java was hard. Whats with all the ">>" why do u need them?

  3. #3
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by -Panda- View Post
    I thought java was hard. Whats with all the ">>" why do u need them?
    << and >> are usually for bit shifting, however in the context of streams(input/output) they're overloaded to pipe text into and out of the stream.

    Also, a note for OP; You're working with integers, try 1 and 2 as input, this will probably result in 1 where you'd want it to return 1.5. See if you can fix that
    Last edited by Hell_Demon; 05-24-2017 at 03:16 AM.
    Ah we-a blaze the fyah, make it bun dem!

  4. The Following User Says Thank You to Hell_Demon For This Useful Post:

    Zombie (05-24-2017)

  5. #4
    xYummyless's Avatar
    Join Date
    Apr 2017
    Gender
    male
    Location
    chiraq
    Posts
    74
    Reputation
    10
    Thanks
    540
    My Mood
    Drunk
    looks cool

  6. #5
    Threadstarter
    Upcoming C++/C# Developer
    Premium Member
    Zombie's Avatar
    Join Date
    Nov 2013
    Gender
    male
    Location
    Clearwater, Florida
    Posts
    414
    Reputation
    52
    Thanks
    93
    My Mood
    Happy
    Quote Originally Posted by Hell_Demon View Post
    << and >> are usually for bit shifting, however in the context of streams(input/output) they're overloaded to pipe text into and out of the stream.

    Also, a note for OP; You're working with integers, try 1 and 2 as input, this will probably result in 1 where you'd want it to return 1.5. See if you can fix that
    Oh shoot this might be hard, I'll see what I can do to make the outcome 1.5!
    Quote Originally Posted by thepieceofshit View Post
    i have another hack

    come pm on mpgh

    u press f1 you get dick in ur butt

  7. #6
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by ZombieCake View Post
    Oh shoot this might be hard, I'll see what I can do to make the outcome 1.5!
    Hint: Use a datatype that supports decimals such as float or double.

  8. The Following 2 Users Say Thank You to WasserEsser For This Useful Post:

    Hell_Demon (05-26-2017),Zombie (05-29-2017)

  9. #7
    殺す必要がある唯一のものは殺されるために準備され人 々である。
    Premium Member
    Hitokiri~'s Avatar
    Join Date
    Oct 2012
    Gender
    female
    Location
    Cancer.
    Posts
    1,201
    Reputation
    24
    Thanks
    937
    My Mood
    Bitchy
    Here's another app you can try out:

    Code:
    /* For std::cin and std::cout */
    #include <iostream>
    
    /* For std::numeric_limits<> */
    #include <limits>
    
    /* For std::unique_ptr<> and std::make_unique<> */
    #include <memory>
    
    int main(int argc, char** argv)
    {
        /* Define the scalar values and initialize them. */
    	auto sum = 0.0, average = 0.0, max = 0.0, min = std::numeric_limits<double>::max();
    	
    	/* Holds the maximum number of numbers the user wishes to calculate for. */
    	auto maxNumbers = 0;
    		
    	/* Request the input from the user. */
    	std::cout << "Enter the number of numbers you'd like to calculate the sum, average and min/max of: ";
    	std::cin >> maxNumbers;
    	
    	/* Prompt the user to enter the numbers. */
    	std::cout << "Please enter " << maxNumbers << " numbers:" << std::endl;
    	
    	/* Allocate N numbers as an array of smart pointers. */
    	auto numbers = std::make_unique< long double[] >( maxNumbers );
    	
    	/* Do the following till we have all numbers. */
    	for(auto i = 0; i < maxNumbers; i++)
    	{
    	    /* Get a number. */
    		std::cin >> numbers[ i ];
    		
    		/* Add it to the sum, thus far. */
    		sum += numbers[ i ];
    		
    		/* Check if the entered number exceeds the maximum stored. */
    		if( numbers[ i ] > max )
    		    /* Update the maximum. */
    			max = numbers[ i ];
    		
    		/* Check if the entered number exceeds the maximum stored. */
    		if( numbers[ i ] < min )
    		    /* Update the maximum. */
    			min = numbers[ i ];
    		
    		/* Friendly user output to indicate they may enter another number. */
    		std::cout << "You entered: " << numbers[ i ] << std::endl;
    	}
    	
    	/* Calculate the average. */
    	average = sum / static_cast<double>(maxNumbers);
    	
    	/* Output the results. */
    	std::cout << "Sum: " << sum << std::endl;
    	std::cout << "Average: " << average << std::endl;
    	std::cout << "Minimum: " << min << std::endl;
    	std::cout << "Maximum: " << max << std::endl;
    
    	return 0;
    }
    You can run it here: https://cpp.sh/8rkg


  10. #8
    Threadstarter
    Upcoming C++/C# Developer
    Premium Member
    Zombie's Avatar
    Join Date
    Nov 2013
    Gender
    male
    Location
    Clearwater, Florida
    Posts
    414
    Reputation
    52
    Thanks
    93
    My Mood
    Happy
    Quote Originally Posted by Hitokiri~ View Post
    Here's another app you can try out:

    Code:
    /* For std::cin and std::cout */
    #include <iostream>
    
    /* For std::numeric_limits<> */
    #include <limits>
    
    /* For std::unique_ptr<> and std::make_unique<> */
    #include <memory>
    
    int main(int argc, char** argv)
    {
        /* Define the scalar values and initialize them. */
    	auto sum = 0.0, average = 0.0, max = 0.0, min = std::numeric_limits<double>::max();
    	
    	/* Holds the maximum number of numbers the user wishes to calculate for. */
    	auto maxNumbers = 0;
    		
    	/* Request the input from the user. */
    	std::cout << "Enter the number of numbers you'd like to calculate the sum, average and min/max of: ";
    	std::cin >> maxNumbers;
    	
    	/* Prompt the user to enter the numbers. */
    	std::cout << "Please enter " << maxNumbers << " numbers:" << std::endl;
    	
    	/* Allocate N numbers as an array of smart pointers. */
    	auto numbers = std::make_unique< long double[] >( maxNumbers );
    	
    	/* Do the following till we have all numbers. */
    	for(auto i = 0; i < maxNumbers; i++)
    	{
    	    /* Get a number. */
    		std::cin >> numbers[ i ];
    		
    		/* Add it to the sum, thus far. */
    		sum += numbers[ i ];
    		
    		/* Check if the entered number exceeds the maximum stored. */
    		if( numbers[ i ] > max )
    		    /* Update the maximum. */
    			max = numbers[ i ];
    		
    		/* Check if the entered number exceeds the maximum stored. */
    		if( numbers[ i ] < min )
    		    /* Update the maximum. */
    			min = numbers[ i ];
    		
    		/* Friendly user output to indicate they may enter another number. */
    		std::cout << "You entered: " << numbers[ i ] << std::endl;
    	}
    	
    	/* Calculate the average. */
    	average = sum / static_cast<double>(maxNumbers);
    	
    	/* Output the results. */
    	std::cout << "Sum: " << sum << std::endl;
    	std::cout << "Average: " << average << std::endl;
    	std::cout << "Minimum: " << min << std::endl;
    	std::cout << "Maximum: " << max << std::endl;
    
    	return 0;
    }
    You can run it here: https://cpp.sh/8rkg

    :O I saw arrays and noped out haha, I've still got some reading to do on this C++ Primer book but once I do get through reading about arrays, I'll come back to your code and see if I can make sense of it. I really appreciated your contribution though! I'm sure it'll be great practice when I get there.
    Quote Originally Posted by thepieceofshit View Post
    i have another hack

    come pm on mpgh

    u press f1 you get dick in ur butt

  11. The Following User Says Thank You to Zombie For This Useful Post:

    Hitokiri~ (05-26-2017)

  12. #9
    Hackinet's Avatar
    Join Date
    Jun 2014
    Gender
    male
    Posts
    525
    Reputation
    260
    Thanks
    1,024
    @ZombieCake float instead of int for getting 1.5

  13. The Following 4 Users Say Thank You to Hackinet For This Useful Post:

    prohacku (06-15-2017),thxtesting (06-15-2017),thxtesting2 (06-15-2017),Zombie (05-29-2017)

  14. #10
    Threadstarter
    Upcoming C++/C# Developer
    Premium Member
    Zombie's Avatar
    Join Date
    Nov 2013
    Gender
    male
    Location
    Clearwater, Florida
    Posts
    414
    Reputation
    52
    Thanks
    93
    My Mood
    Happy
    Quote Originally Posted by Hackinet View Post
    @ZombieCake float instead of int for getting 1.5
    Yes I defined them as floats instead of integers and it worked fine! I just forgot to come back and update. Thanks for all the help guys!
    Quote Originally Posted by thepieceofshit View Post
    i have another hack

    come pm on mpgh

    u press f1 you get dick in ur butt

  15. #11
    csgocheatxddd123's Avatar
    Join Date
    Feb 2017
    Gender
    male
    Location
    Pakistan
    Posts
    26
    Reputation
    10
    Thanks
    0
    My Mood
    Bored
    Zombie, try this.(and Yes its my code)
    Ask me if you don't understand, Its pretty basic code with functions and loops.

    You can also find power by using loop instead of using "math.h" library. Try that!

    Code:
    #include "iostream"
    #include "conio.h"
    #include "math.h"
    
    using namespace std;
    
    float areaC(float);
    float areaR(float, float);
    float add(float, float);
    float sub(float, float);
    float mul(float, float);
    float div(float, float);
    float power(float, float);
    float factorial(float number);
    void fibonacci();
    void average();
    void mean();
    
    void menu();
    
    int main()
    {
    	float x = 0, y = 0, result = 0;
    	int choice;
    
    	menu();
    	choice=getch();
    
    	switch (choice)
    	{
    	case 49:
    		cout << "Enter number 1 and 2: ";
    		cin >> x >> y;
    
    		result = add(x, y);
    		cout << "Addition result of both numbers is: " << result;
    		break;
    
    	case 50:
    		cout << "Enter number 1 and 2: ";
    		cin >> x >> y;
    
    		result = sub(x, y);
    		cout << "Subtraction result of both numbers is: " << result;
    		break;
    
    	case 51:
    		cout << "Enter number 1 and 2: ";
    		cin >> x >> y;
    
    		result = mul(x, y);
    		cout << "Multiplication result of both numbers is: " << result;
    		break;
    
    	case 52:
    		cout << "Enter number to find its square: ";
    		cin >> x;
    
    		result = power(x, 2);
    		cout << "Square of number \""<<x<<"\" is: " << result;
    		break;
    
    	case 53:
    		cout << "Enter number to find its cube: ";
    		cin >> x;
    
    		result = power(x, 3);
    		cout << "Cube of number \""<<x<<"\" is: " << result;
    		break;
    
    	case 54:
    		cout<<"Enter the number to find its factorial: "<<endl;
    		cin>>x;
    		cout<<"Factorial of the number is "<<factorial(x)<<endl;
    		break;
    
    	case 55:
    		fibonacci();
    		break;
    
    	case 56:
    		average();
    		break;
    
    	case 57:
    		mean();
    		break;
    
    	default:
    		cout << "wrong choice";
    	}
    
    	_getch();
    	return 0;
    }
    
    float add(float x, float y)
    {
    	return x + y;
    }
    float sub(float x, float y)
    {
    	return x - y;
    }
    float mul(float x, float y)
    {
    	return x * y;
    }
    float power(float x, float y)
    {
    	return pow(x, y);
    }
    float factorial(float number)
    {
    int temp=number;
    for(int i=number-1;i>=2;i--)
    {
    temp=temp*i;
    }
    return temp;
    }
    void fibonacci()
    {
    	{
        int n, t1 = 0, t2 = 1, next = 0;
        cout << "Enter the number of terms in fibonacci series: ";
        cin >> n;
     cout<<endl;
        for (int i = 1; i <= n; ++i)
        {
         
            if(i == 1)
          {
                cout << " " << t1;
                continue;
        }
            if(i == 2)
          {
                cout <<" "<< t2 << " ";
                continue;
          }
            next = t1 + t2;
            t1 = t2;
            t2 = next;
            cout << next << " ";
         }
         }
    }
    void average()
    {
    	int j=0,x=0,result=0;;
    		cout<<"Enter total amount of numbers to find average of: "<<endl;
    		cin>>j;
    		for(int i=0;i<j;i++)
    		{
    			cout<<"Enter number "<<i+1<<":";
    			cin>>x;
    			result=x+result;
    		}
    		cout<<"Average result of numbers is "<<result/j;
    }
    void mean() //or called midrange otherwise mean is same as average^^
    	//Mean or Midrange is the smallest number + largest number divided by 2.
    {
    	int x=0,result=0;
    	cout<<"Enter the integers to find their mean, enter 99 to end."<<endl;
    	cin>>x;
    
    	int max=x;
    	int min=x;
    	while(true)
    	{
    		cin>>x;
    		if(x==99){
    	     break;
    		}
    		else if(x>max){
    			max=x;
    		}
    		else if(x<min){
    			min=x;
    		}
    	}
    	result=max+min;
    	cout<<"Mean or Midrange result of the numbers is "<<result/2;
    }
    void menu()
    {
    	cout << "1) Press 1 for Addition .\n2) Press 2 for Subtraction \n"<<
    		"3) Press 3 for Multiplication.\n4) Press 4 for Square.\n5) Press 5 for Cube.\n6) Press 6 for Factorial."<<
    		"\n7) Press 7 for Fibonacci series.\n8) Press 8 for Average.\n9) Press 9 for Mean."<< endl<<endl<<endl;
    }

Similar Threads

  1. Simple KDR Calculator
    By MvRouC12 in forum CrossFire Discussions
    Replies: 14
    Last Post: 05-07-2010, 06:59 AM
  2. Super Simple ESP?
    By Daygum in forum Call of Duty Modern Warfare 2 Help
    Replies: 7
    Last Post: 04-24-2010, 09:03 PM
  3. [Release] [CS 1.6] Super Simple Wall v6.7 by <:PrOdIgY:> AKA Jimster480
    By Jimster480 in forum CounterStrike (CS) 1.6 Hacks / Counter Strike: Source (CSS) Hacks
    Replies: 0
    Last Post: 01-08-2010, 06:29 AM
  4. [Release] [CS 1.6] Super Simple Wall v6.6 by <:PrOdIgY:> AKA Jimster480
    By Jimster480 in forum CounterStrike (CS) 1.6 Hacks / Counter Strike: Source (CSS) Hacks
    Replies: 10
    Last Post: 01-07-2010, 09:15 AM
  5. [Release] Super Simple Wall v6.5
    By rfbtgn in forum CounterStrike (CS) 1.6 Hacks / Counter Strike: Source (CSS) Hacks
    Replies: 3
    Last Post: 12-10-2009, 08:35 AM