sfuo 111

Here is a rough example of why you would want to use it.

If you comment out [ICODE]fflush(stdin);[/ICODE] then it skips asking for input every second one, but with it you get asked every time.

[CODE]#include <stdio.h>

include <stdlib.h>

int main()
{
int i = 1;
char input;
while(1)
{
printf("\n\nLoop number %d - input 'Y' or 'y' to stop\n", i);
fflush(stdin);
scanf("%c", &input);
if( input == 'y' || input == 'Y' )
break;
i++;
}

return 0;

}
[/CODE]

WaltP commented: Flushing stdin is undefined. Do NOT do it. -4
sfuo 111

You don't need to make them a string you could just use %10 and /10 to figure out the 1s and 10s digit then add those 2 numbers together to check.

Edit: Didn't even read the whole post until after mine and it says right in there how to do it.

thelamb commented: Good job quoting his assignment. +0
sfuo 111

You can look over this and see what is going on but as you will notice I commented in most of the stuff it is missing from being complete.

[CODE]#include <iostream>
using namespace std;

void DisplaySeats( char seats[][4], int rows )
{
for( int i = 0; i < rows; i++ )
{
cout << i+1 << " ";
for( int c = 0; c < 4; c++ )
cout << seats[i][c] << " ";
cout << endl;
}
cout << endl;
}

int main()
{
string input;
int rows = 7; //amount of rows
char seats[rows][4]; //holds seat information
char aRow[] = {'A', 'B', 'C', 'D' }; //only used to assign seats array

for( int i = 0; i < rows; i++ )
    for( int c = 0; c < 4; c++ )
        seats[i][c] = aRow[c]; //assigns the seats array

DisplaySeats(seats, rows); //displays the seats

//start a loop here

cout << "Please enter your seat (i.e. 4B):" << endl; //include some way to break the loop
getline(cin, input);

//come up with better error checking and maybe remove all spaces for cases if someone types "4 B" instead of "4B"
//does not check if seat is already taken
if( input.length() < 2 ) //if input is too short (doesnt check if its too long)
{
    cout << "invalid input" << endl;
    system("PAUSE");
    return 0;
}

if(( input[0] < (int)'1' || input[0] > (int)'7' ) || ( input[1] < (int)'A' || input[1] > (int)'D')) //checks if the input is ok (doesnt ...
sfuo 111

namespaces are out of date IMO so if you are using them I think you are just making stuff more complex.

sfuo 111

Here is what I came up with.

"mystuff.h"
[CODE]#ifndef MYSTUFF_H

define MYSTUFF_H

void randomize();

int random( int high, int low = 0);

int getMax( int A[] );

int getMin( int A[] );

int swap( int A[] );

endif

[/CODE]

"mystuff.cpp"
[CODE]#include <time.h>

include <stdlib.h>

include "mystuff.h"

void randomize()
{
srand(time(NULL));
}

int random( int high, int low )
{
return rand() % (high-low) + low;
}

int getMax( int A[] )
{
int max = A[0];
for( int i = 1; i < 10; i++ )
{
if( A[i] > max )
{
max = A[i];
}
}
return max;
}

int getMin( int A[] )
{
int min = A[0];
for( int i = 1; i < 10; i++ )
{
if( A[i] < min )
{
min = A[i];
}
}
return min;
}

int swap( int A[] )
{
for( int i = 0; i < 10; i++ )
{
int temp = A[i];
int ran = random(10);
A[i] = A[ran];
A[ran] = temp;
}
return A[10];
}
[/CODE]

"array.cpp"
[CODE]#include <iostream>

include "mystuff.h"

using namespace std;

int main()
{
//declare variables and set random seed
int A[10], min, max;
randomize();

//make random numbers and assign to array
for(int i = 0; i < 10; i++)
{
    A[i] = random(100, -100);
}

//find min and max numbers in array
min = getMin( A );
max = getMax( A );

//output array before shuffled

for( int i = 0; i < 10; i++ )
{
    if( i != ...
mvmalderen commented: Since when do we provide free cookies? -4