mercredi 27 décembre 2017

else if (a != 65);

#include <iostream>
#include <Windows.h>
using namespace std;

void noret()
{

    for (int i = 1; i < 11; i++)
    {
        cout << "Line number : " << i << endl;
    }

    system("pause");
}

void StartProgram(string filename)
{
    ShellExecute(NULL, "open", filename.c_str(), NULL, NULL, SW_SHOWNORMAL);
}

int main()
{
    for (int a = 1; a < 100; a += 3)
    {
        cout << "The number is: " << a << endl;
        if (a == 65)
        {

            StartProgram("mspaint");
        }
        else if (a != 65);
        {
            StartProgram("devenv");
        }
    }
    system("pause");
    return 0;

}

Here is the code I made(I am still new to programming). Please ignore the void noret() part. The code is Fully working, but in the part with else if (a != 65), I want to make it open the program only if it isn't equal to 65.

The program counts from 1-100. a = a+3 where "a" is equal to 1. While it counts to 100, if "a" is never equal to 65 it will open "devenv". But the way I did it it's made that "devenv" will open to very number that isn't equal to 65. How can I make it so that it will open ONCE if throughout the counting it never was 65... Does it make any sense?

Aucun commentaire:

Enregistrer un commentaire