Questions/Assistance

I have a couple short answer questions that I need help with. I have gotten a few but needed some assistance with others.

1. Given the array int x [ ] = {1,2,3,4,5}, write a loop that multiplies every element by 2.
MY ANSWER
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
int x[] ={1,2,3,4,5};
for(int i=0;i < 5; i++) cout << x[i]*2 <<endl;
system("Pause");
return 0;
}

2.int a = 7, b= 10, c= 4;
what is the result of :
( (a < b) || (b > c)) && (c < a)
MY ANSWER
( (a < b) || (b > c)) && (c < a)
( (7 < 10) || (10 > 4)) && (4 < 7)
( (true) || (true) ) && (true)
(true) &&(true)
TRUE

3 Write a switch statement that uses int x (a number read from the keyboard) and prints to the
screen the following:
" It is a even" if the value of x was even; "It is odd" if the value of x was odd
HELP !!!

4.Write a function change that accepts an int array, and int representing the length of that array
and an int value as parameters, and stores the integer value into the last element of the array. The original array SHOULD be changed.
HELP !!!
1. Given the array int x [ ] = {1,2,3,4,5}, write a loop that multiplies every element by 2.

It doesn't necessarily say to display them, but just to multiply them. I'm assuming your teacher wants you to physically change the values in the array

3 Write a switch statement that uses int x (a number read from the keyboard) and prints to the
screen the following:

This one is actually pretty easy, if you know C++. I don't understand why you're supposed to use a switch statement, but a way around that is to use the default case. A test to see if a number is odd or even is to use the modulus operator, %, which returns a remainder from integer division.

Write a function change that accepts an int array, and int representing the length of that array
and an int value as parameters, and stores the integer value into the last element of the array. The original array SHOULD be changed.

Your teacher needs to invest in grammar checker. Essentially, this is saying, write a function, named "change" that accepts 3 parameters. The first being the array, the second being the array size, and the third being an int value.

Once you can write that prototype, you need to read what the last part says. Store the value into the last element of the array. Well, that's simple. An array of size n has elements from 0 - (n-1). Therefore, n-1 is the last element. All you need to do is set the last element equal to value.
Topic archived. No new replies allowed.