-
June 22nd, 2009, 11:58 AM
#1
What am I missing?
I get a pointer error when compiling.
#include <iostream>
#include <cstdlib>
using namespace std;
void sort (int, int);
int main ()
{
int total = 0.0, average;
int numscores, counter;
cout << "Enter number of test scores: ";
cin >> numscores;
int *scores = new int[numscores];
for (int counter = 0; counter < numscores; counter++) // Enter values
{
do
{
cout << "Enter test score " << (counter + 1) << ": ";
cin >> scores[counter];
if (scores[counter] < 0)
{
cout << "Invalid entry! ";
cout << endl;
}
} while (scores[counter] < 0);
}
cout << endl;
sort(scores, numscores);
for (int counter = 0; counter < numscores; counter++) // total
total += scores[counter];
average = (total / numscores); // average
for (counter = 0; counter < numscores;counter++) // Print scores
{
cout << scores[counter] << endl;
}
cout << endl;
cout << "Average: " << average << endl;
system("pause");
return 0;
}
void sort (int tests[], int numtests)
{
int temp, count;
bool swap;
do // Sort
{
swap = false;
for (int count = 0; count < (numtests - 1); count++)
{
if (tests[count] > tests[count - 1])
{
temp = tests[count];
tests[count] = tests[count + 1];
tests[count + 1] = temp;
swap = true;
}
}
} while (swap == false);
}
-
June 22nd, 2009, 12:07 PM
#2
Re: What am I missing?
I get a pointer error when compiling.
Do we have to guess which one ?
btw. .. this doesn't give you a average. Divisions like these only work when you use type 'double' as variables.
Code:
average = (total / numscores); // average
-
June 22nd, 2009, 12:30 PM
#3
Re: What am I missing?
the error comes from the scores pointer
Thanks.
-
June 22nd, 2009, 12:49 PM
#4
Re: What am I missing?
Code:
void sort (int, int);
void sort (int tests[], int numtests)
These are not the same.
-
June 22nd, 2009, 12:51 PM
#5
Re: What am I missing?
What exactly is the error(s)?
-
June 22nd, 2009, 01:05 PM
#6
Re: What am I missing?
error C2664: 'sort' : cannot convert parameter 1 from 'int *' to 'int'
1> There is no context in which this conversion is possible
-
June 22nd, 2009, 01:07 PM
#7
Re: What am I missing?
Lindley,
Thank you. It seems that adding the [] in the prototype did the trick.
Scott
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|