Hey!! I'm new to C++, this is the final program of my semester and I am stuck sooooo hard...
I have the code laid out and it will compile but my functions wont work like I want them too. here is the code:
#include<iostream>
using namespace std;
void getlist(int[], int&);
void putlist (const int[], int);
float mean_average (const int[], int);
int MinIndex (const int[], int);
void left_rotate (int[], int);
const int MAXSIZE = 50;
int main()
{
int mylist[MAXSIZE];
int num_items;
getlist (mylist, num_items);
putlist (mylist, num_items);
MinIndex (mylist, num_items);
mean_average(mylist, num_items);
left_rotate (mylist, num_items);
system ("PAUSE");
return 0;
}
void getlist(int mylist[], int &num_items)
{
cout << "Enter the number of Array Elements, Maximum " << MAXSIZE << endl;
cin >> num_items;
for (int i = 0; i < num_items; i ++)
{
cout << "Enter the next array element\n";
cin >> mylist[i];
}
}
void putlist (const int mylist[], int num_items)
{
cout << "Array elements\n";
for (int i = 0; i < num_items; i ++)
{
cout << i << " " << mylist [i] << endl;
}
}
int MinIndex (const int mylist[], int num_items)
{
int min =mylist[0];
for(int i = 0; i < num_items; i++)
{
if (min <= mylist[i])
min = i;
}
cout<< "The address of the smallest number is "<< min<<endl;
return min;
}
float mean_average(const int mylist[],int num_items)
{
int sum=0;
float average;
for(int i= 0; i <= num_items; i++)
{
sum= sum + mylist[i];
}
average= sum/num_items;
cout<< "The average value is: "<<average<<endl;
return average;
}
void left_rotate (int mylist[], int num_items)
{
int temp = mylist[0];
for(int i = 0; i < num_items-1; i++)
{
cout << "The new array elements are:\n";
mylist[i] = mylist[i+1];
cout << i << " " << mylist [i]<<endl;
mylist[num_items-1] = temp;
cout<<temp;
}
}
The array left rotate does rotate but the value stored in temp wont appear, and the calculations for MinIndex and mean_average are just not working out.... I've looked all over the web, but even when I find codes that are identical they still don't work. what am I doing wrong?? I would write it simpler but the format is require and all the functions were dictated so I cant alter them. This is due tuesday- please help!!