mercredi 24 février 2016

Putting an IF statement inside a Loop?

I am trying to write a program that accepts inputs of even numbers until the user enters a odd number then it stops and adds all the even inputs. The problem I am having is that I'm intending to use an If statement to determine if the number is even or not but once the program has run I need it to run again so the user can keep inputting numbers until they input a odd one.

Here's what I have so far:

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    int value;
    cout << "Please enter a possitive number: ";
    cin >> value;
    if (value%2 == 0) { // divides the value entered by 2 too determine whether or not its even.
        cout << "Please enter another even number: ";
    }
    else
    {

}

cin.get();
return 0;
}

Aucun commentaire:

Enregistrer un commentaire