We will get you through this. First of all, line 15: You don't need to square the amount of numbers. You need to square the numbers that the user inputs later on in the program.
And about the function: I was trying to lean you towards making a simple void function to square the numbers.
(There are actually a good many ways you could get the squaring done, but since you're learning vectors now, I feel like you must have covered user defined functions recently.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include<iostream>
#include<vector>
using namespace std;
void squareNum(int&); // prototype for function to square num of int data type
vector<int> numbers; // vector to hold numbers input by user
vector<int> numsSquared; // vector to hold numbers squared
int main()
{
int amount; // stores the users desired amount of numbers
int num; // receives the numbers input by user and passes them to vectors via .push_back(num);
} // end main
|
As for Reversing the loop, I want you to think about how arrays/vectors work.
Just write down in words what you need to loop to do, and then make it happen.
Start by thinking about the variables you are using. Remember how you prompted the user for the amount of numbers they wanted to work with?
(Its the "int amount" in my code). So we say, "The amount of times this loop needs to cycle = the amount of numbers the user asked for."
You kind of answered this question yourself when you typed the word "reversing". Well, we used i++ to go frontwards. So we should do what to i to do the opposite?