Random Selection without replacement

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <stdio.h>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	clock_t start;   /* Line 8 */
    clock_t finish;  /* Line 9 */
	const int arraysize=36;
	const int SelectN=6;
	int row[SelectN];
	int Crows=100;
	int g;
	int arraycounter=arraysize;
	int a[arraysize+1];
	start = clock();
	srand(60);
	for (int k=0;k<Crows;k++)
		{
		arraycounter=arraysize;
		for(int i=0; i<=arraysize;i++) {a[i]=i;}
			for(int i=0; i<SelectN;i++) 
				{	g=rand()%arraycounter;
					row[i]=a[g];//fill the row array
					//cout<<"g: "<<g<<"=>|"<<a[g]<<"|";
					cout<<" "<<a[g];
					a[g]=a[arraycounter];
					arraycounter--;
				}
		cout<<endl;
		}

	cout<<endl<<endl<<endl<<endl<<endl;
	finish = clock() - start;
    double interval = finish / (double)CLOCKS_PER_SEC; 
	cout<<endl;
	printf("%f clock cycles", finish); cout<<endl;  
	printf("%f seconds elapsed", interval);cout<<endl;
	system("PAUSE");
	return 0;
}

one loop and a decision

very very basic for loop and if else if else

#include <iostream>
using namespace std;
int main()
{
int i;
for(i=0;i<=13;i++)
    {cout << "Hello world! "<< i <<endl;};
if(i==13)
    {cout << "If satisfied with: "<< i <<endl;}
else if(i==12)
    {cout << "Else If satisfied with: "<< i <<endl;}
else
    {cout << "Else satisfied with: "<< i <<endl;};
    return 0;
}

..notice that by the time it leaves the

for (){}

loop it is 14 not 13

Want system pause?

system("PAUSE");

then you’ll need:

#include <stdlib.h>

Preprocessor directives

An example of some preprocessor stuff:

#include <iostream>
#define __thing__ " amazing "
#define __func__(x,y) ((x)>(y)?(x):(y))
#define _FAT_
#define _Cars_
using namespace std;
int main()
{
     cout << "Hello world!"<< __thing__ <<endl;
     cout<<__func__(11,10)<<endl;
     //because we are not passing variables everything is groovy
    int g=70,f=90;
    cout<<__func__(g,f)<<endl;
    #ifdef _FAT_
        cout<<"FAT"<<endl;
    #else
        cout<<"notfat"<<endl;
    #endif

    #ifndef _Cars_
        cout<<"Cars not defined"<<endl;
    #else
        cout<<"Cars defined"<<endl;
    #endif
    cout<<__LINE__<<endl;
    cout<<__LINE__<<endl;
    cout<<__LINE__<<endl;
    cout<<__FILE__<<endl;
    cout<<__DATE__<<endl;
    cout<<__TIME__<<endl;
    cout<<__STDC__<<endl;
    cout<<__cplusplus<<endl;
    return 0;
}

C++ MFC

Make sure:

#include "stdafx.h"

comes FIRST otherwise you will get lots of proper errors.

If you see the following error:

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

Make sure that your linker is set to compile for windows:

Project > Properties > Linker > System > SubSystem
set to
Windows (/SUBSYSTEM:WINDOWS)

Another key hint is to set your

Project > Properties > Configuration Properties > General > Use of MFC

set to:

Use MFC in a Shared DLL