+ 1

What if you want to add a varying number of inputs to the function. i.e. you want it to perform addition for 1, 2, 3 , 4 or 5

Cpp

9th Aug 2019, 9:26 AM
JeClives
7 Réponses
+ 1
How I'm c++
9th Aug 2019, 11:55 AM
JeClives
+ 1
What if I want the user to vary the size Say for example A function where the user puts in any number of inputs. And it gives the sum of all and subtracts the last
9th Aug 2019, 12:41 PM
JeClives
0
You can use a table.
9th Aug 2019, 11:49 AM
Qermon
Qermon - avatar
0
int myFunc(int arr[]) { }
9th Aug 2019, 11:58 AM
Qermon
Qermon - avatar
0
However, you may also want to pass the size so int myFunc(int arr[], int size) { }
9th Aug 2019, 12:01 PM
Qermon
Qermon - avatar
0
I'm not that good in cpp but I'll assist you. It seems you're trying to add number 1 to 5 within a function, if that's the case then try this out: a =1 and b = 2 which would be passed to the function as shown int myFunc(int a, int b) { int c; c = a +b; while (b < 5){ b++; c = c + b; } return c; } So within your main function just send in the values int main() { int value1= 1; int value2 = 2; myFunc(value1, value2); } Hope this helps.
9th Aug 2019, 1:07 PM
Austin.O
Austin.O - avatar