Visual Express 2008, No input window?

Hey I built my program without a problem, I try to run/debug it and I am getting a message that it has exited with code 0. Why isnt a window popping up asking for input? This program inputs numbers and gives the sum of the evens and odds. What am I doing wrong the code looks good?

#include "header2.h"

using namespace std;

int main ()

{

int limit;

int counter;

int number;

int evensum;

int oddsum;

limit = 0;

counter = 0;

number = 0;

evensum = 0;

oddsum = 0;

cout<<"This program takes a set of numbers"<<endl;

cout<<"and gives the sum of the even and odd numbers"<<endl;

cout<<"enter the amount of numbers"<<endl;

cin>>limit;

cout<<"Please enter "<<limit<<" numbers"<<endl;

while(counter < limit)

{

cin>>number;

if(number % 2 == 0)

evensum = evensum + number;

else

oddsum = oddsum + number;

counter++;

}

cout<<"The sum of the even numbers is "<<evensum<<endl;

cout<<"The sum of the odd numbers is "<<oddsum<<endl;

return 0;

}

Update:

Sorry, iostream is in the header file.

Comments

  • The window closes fast because your program completes. Put the following before the return 0; and you program will stay open until you enter a number.

    cin>>number;

  • you need to include the input output stream

    like this:

    #include <iostream>

    and maybe add a cin at the end so you can see the result before it exits, like this:

    cout<<"The sum of the even numbers is "<<evensum<<endl;

    cout<<"The sum of the odd numbers is "<<oddsum<<endl;

    cin>>limit;

    return 0;

Sign In or Register to comment.