those types of messages are cryptic to read at first, but they tell you exactly what the problem is. It probably really says cant convert int* to int or int[] to int or something, post the exact message next time.
here:
grades = curve(scores); //curve takes an int. scores is not an int, scores is an array.
also, I HIGHLY recommend not using the same variable name twice in one file. You can do it, but it just causes problems for the reader and writer. Here, you have 2 versions of 'scores'.
ok i get that now but how would you recommend solving this? Would i call each array scores[1-6] individually and parse them or would there be a simpler way? The scores have to be passed to a function and sent back to main or else i would've had the code done by now. also can you explain it so a pea brain like me can understand it? I really do want to learn this.
sorry bout all this people do tend to tell me i am overthinking things.
I don't know what function int curve(int); is supposed to do. The declaration says that it receives a single integer as a parameter and returns a single integer. I just made a simple version which returns the input multiplied by 2.
#include <iostream>
usingnamespace std;
int curve(int);
int main ()
{
constint NUM_SCORES = 6;
int scores[NUM_SCORES];
int count;
int grades;
cout << "Enter the scores for the " << NUM_SCORES << " tests: ";
for (count = 0; count < NUM_SCORES; count++)
cin >> scores[count];
cout << "The scores you entered are: ";
for (count = 0; count < NUM_SCORES; count++)
cout << " " << scores[count];
cout << endl;
cout << "The curved scores are: ";
for (count = 0; count < NUM_SCORES; count++)
{
grades = curve(scores[count]);
cout << " " << grades;
}
}
int curve(int scores)
{
int result = scores * 2;
return result;
}
Enter the scores for the 6 tests: 1
2
3
4
5
6
The scores you entered are: 1 2 3 4 5 6
The curved scores are: 2 4 6 8 10 12
Back to the function:
1 2 3 4 5 6
int curve(int scores)
{
int curve = 10;
scores + curve;
}
There are several problems here. Line 3. int curve = 10; A variable is declared with the same name as the function itself. The compiler permits this, but it looks like a recipe for confusion. If we say 'curve' do we mean the function or the variable?
Line 5, scores + curve; this adds two integers, but doesn't do anything with the total. That line may as well not be there at all since it has no effect on anything.
Line 6. A serious problem. The closing brace of the function is reached, but it did not return any value. It promised in the function header that it would return an integer value. There should be a return statement there which does return whatever integer value is appropriate.
if you want to process an array into one answer, you need something like:
1 2 3 4 5 6 7
int curve(int * s, int length)
{
for(int j = 0; j < length; j++)
do something to s[j];
return some_answer;
}
if you want to process 1 entry of an array to get 1 answer each:
1 2 3 4 5 6 7 8 9 10 11 12
int curve(int s)
{
do something to s;
return some_answer;
}
and call that in main with:
for(j = 0; j < size; j++)
{
result = curve(scores[j]);
.. do something with result ..
}
you can combine the 2 ideas and return an array of answers, as a third approach.
which of these you need depends on what you want to do.
What i need to do is write a program to fill an array with six test scores, add 10 points to each score and display the revised score. Do not use a function. Just write it all in main( );
Then once I have accomplished that go back and put the calculation in a function. main() will prompt for and accept a value, pass the value to the function, but instead of returning the value with a return statement, try it with a call by reference (or a reference variable that refers to the memory location of the original value.) main() will display the result.
im down to one error code now thanks so very much for your help. I get this error: expected primary-expression before int. so its expecting me to put int into a function?
#include <iostream>
int curve(int);
int main ()
{
constint NUM_SCORES = 6;
int scores[NUM_SCORES];
std::cout << "Enter the scores for the " << NUM_SCORES << " tests: ";
for( int& v : scores ) std::cin >> v ; // http://www.stroustrup.com/C++11FAQ.html#for
std::cout << "The scores you entered are: ";
for( int v : scores ) std::cout << v << ' ' ;
std::cout << '\n' ;
std::cout << "The curved scores are: ";
for( int v : scores ) std::cout << curve(v) << ' ' ;
std::cout << '\n' ;
}
int curve( int score )
{
// return the 'curved' value of the score
return score + 10;
}
#include <iostream>
void curve( int& score ) ;
int main ()
{
constint NUM_SCORES = 6;
int scores[NUM_SCORES];
std::cout << "Enter the scores for the " << NUM_SCORES << " tests: ";
for( int& v : scores ) std::cin >> v ; // http://www.stroustrup.com/C++11FAQ.html#for
std::cout << "The scores you entered are: ";
for( int v : scores ) std::cout << v << ' ' ;
std::cout << '\n' ;
// update the scores with the 'curved' value
for( int& v : scores ) curve(v) ;
std::cout << "The curved scores are: ";
for( int v : scores ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
void curve( int& score )
{
// update the score with its 'curved' value
score += 10;
}
@Shiro12 This might be what you are trying to do. 'curve' to me is a not-so-good name because it could mean a whole lot of things. The reason the output was strange is probably because you are adjusting an array and not a single value so the output is junk.