I have school homework to write a C++ program that reads an array and then adds +5 to the values via another function.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
float subtotal (float[], int);
int main() {
int arraySize;
cout << "Enter array size: ";
cin >> arraySize;
float array[arraySize];
cout << "Enter an array size of " << arraySize << " : ";
for (int i=0; i<arraySize; i++){
cin >> array[i];
}
for (int i=0; i<arraySize; i++){
array [i] = subtotal (array[i], arraySize);
cout <<left<<setw(5)<< array [i];
}
return 0;
}
float subtotal (float array[], int arraySize){
float x = array[]+5;
return x;
}
I get this error:
main.cpp: In function 'int main()':
main.cpp:30:49: error: cannot convert 'float' to 'float*' for argument '1' to 'float subtotal(float*, int)'
array [i] = subtotal (array[i], arraySize);
^
what I'm I doing wrong? what does the error mean?
edit: So I matched my decelerations and now I get this error:
main.cpp: In function 'int main()':
main.cpp:30:49: error: cannot convert 'float' to 'float*' for argument '1' to 'float subtotal(float*, int)'
array [i] = subtotal (array[i], arraySize);
^
main.cpp: In function 'float subtotal(float*, int)':
main.cpp:38:21: error: expected primary-expression before ']' token
float x = array[]+5;