I am new to C++ and I was wondering if anyone could help me start off or by guiding me to which method of steps I should take first in solving the following problem:
write a c++ program that with a loop structure that reads in 5 intergers one by one,
calculate the sum of the even values that are read and display the final result.
Any suggestion or comments in regards to the starting point of this problem would be much apprieciated.
try using an array instead of making 5 variable...
if you still dont get it then read on for the code...
int x[5],sum=0; // creates an array to store 5 integers
for(int i=0;i<5;i++) // loop to take 5 values and evaluate them
{
cin>>x[i];
if(x[i]%2==0) // checks if the nubmer is even or not
{ sum=sum+x[i];
}
}
cout<<sum;
I haven't been shown using an array as yet. I have only been shown the following techniques, and they are:
1. If statement, nested statement (i.e else if) and briefly on the following loop (for, while and do) as well as a bit of increment i.e number++
Could some one please suggest a technique I could use? i.e. for or while loop or something.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.