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

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




Need Help With Functions In C++

 
Reply to this topicStart new topic

Need Help With Functions In C++

michael1201
7 Jul, 2008 - 09:09 AM
Post #1

New D.I.C Head
*

Joined: 2 Jul, 2008
Posts: 13

ok so the first part of my assignment was to write a program that used arrays to calculate the max number, minimum numbers, and average number. i completed that part and the second part of the assignment was to write the same program using the following functions

int main();
void take_input(int A[]);
float Calculate(int A[]);
void print_output(int A[]);

and not allowed to use global variables. if anyone could help me i would appreciate it im new to c++ second week and im not very familiar with arrayas and functions. here is my cod


CODE

#include <iostream>
using namespace std;

int main()
{
    int item[10000];
    int sum;
    int counter;
    float numbers;
    float avg;
    double largest;
    

    // AVEREAGE N NUMBERS
    cout<<"how many numbers do you want to average: ";
    cin>>numbers;
    cout<<"Enter Numbers To Avg; ";
    sum = 0;
    for (counter=0; counter < numbers; counter++)
    {    cin>>item[counter];
        sum = sum + item[counter];
    }
    cout<<endl;
    avg = sum/numbers;
    cout<<"The Avg of the numbers is equal to "<<avg<<endl<<endl;


// MAX NUMBER
    int max = item[0];

    for (int counter=1;counter<numbers;counter++)
    {
    if(max<item[counter])
    max=item[counter];
    }
    cout<<"The Max Numbers Is: "<<max<<endl;

// MINIMUM NUMBER
    int min = item[0];
    for (int counter=1;counter<numbers;counter++)
    {
    if(min > item[counter])
    min = item[counter];
    }
    cout<<"The Min Numbers Is: "<<min<<endl;

// Greater Or Less Than Avg
    cout<<endl;
    for (counter=0; counter < numbers; counter++)
    {
        if(item[counter] > avg)
            cout<<item[counter]<<" Is greater than avg"<<endl;
        if(item[counter] < avg)
            cout<<item[counter]<<" Is less than avg"<<endl;
        if(item[counter] == avg)
            cout<<item[counter]<<" Is equal to avg"<<endl;
    }
        




    system("pause");
    return 0;
}

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 01:19PM

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