Fix an almost complete program? Alternating Sum Program

Basically what I'm trying to do is make a program that excepts a variable amount of numbers such as 12, 4, 6 ,7, 9 and make it come out as 12-4+6-7+9 and have a total of those numbers. My logic was to try and take the array elements and if they were even make it add and if the element was odd make it subtract. Since 12 is in element one and element one is odd it should subtract. Let me know if I'm not making it clear I dont have a clear understadning myself. Basically the program I've typed compiles ok but i cant input a second number without a crash. Any help is appreciated! I have to use arrays for this assignment.

#include <iostream>
using namespace std;

int main ()
{
 cout << "Please enter three numbers: " << endl;
 
 const int numb = 3;
 int values[numb];
 double total = 0;
 int i;
 int pos;

 cin >> values[i];
 
 if (values[pos]%2 == 0)
 {
  for (int i = 0; i < numb; i++)
  {
      total = total + values[i];
  }}
  else
  {
  for (int i =0; i < numb; i--)
  {
      total = total - values[i];
  }}
   cout << total << endl;
 system ("pause");
 return 0;
}
First, use [code][/code] tags; they preserve formatting much better than what you used.

As for your problem, check your second for loop. You assign i to 0, then start subtracting numbers from it, but your continue condition is i < numb.
Ok I see what your saying about the second for loop but what should I do to it? set int i to something else?
Topic archived. No new replies allowed.