conversion.h

// Programmer: Simon Thougaard

// File: conversion.h

// Purpose: Header file, declaring functions and useful constants

// for converting numbers from different number bases

#ifndef CONVERSION_H

#define CONVERSION_H

// The range of x and n

const int MAX_X = 99999;

const int MIN_X = 0;

const short MAX_N = 9;

const short MIN_N = 2;

const int MAX_DIVISOR = 10000; // Useful for finding the 5th digit

const short MAX_ATTEMPTS = 3;

// displayMenu() prints a nice menu to cout

// Pre: None

// Post: The menu has been displayed

void displayMenu();

// promptForX() prompts a user for a number

// The user has 3 attempts to enter a number within range

// Pre: None

// Post: The user has either entered a valid number into x,

// or exceeded the number of attempts.

// xSet has been set to 'true' if x is valid,

// xSet has been set to 'false' if x is invalid

void promptForX(int & x, bool & xSet);

// promptForN() prompts a user for a base

// The user has 3 attempts to enter a number within range

// Pre: None

// Post: The user has either entered a valid number into n,

// or exceeded the number of attempts.

// nSet has been set to 'true' if n is valid,

// nSet has been set to 'false' if n is invalid

void promptForN(short & n, bool & nSet);

// checkValidPair() determines if x is a valid base n number

// Pre: x is in the valid range

// n is in the valid range

// Post: true has been returned if x is a valid base n number, false otherwise

bool checkValidPair(const int x, const short n);

// forceN() returns a new value that is the smallest valid n

// Pre: x is in the valid range

// Post: the smallest valid n has been returned

short forceN(const int x);

// forceN() returns a new value for x, where individual invalid digits of x

// has been replaced with randomly selected valid digits

// Pre: x is in the valid range

// n is in the valid range

// rand() has been seeded

// Post: A valid base n number has been returned. Only the invalid digits have

// been replaced

int forceX(const int x, const short n);

// convert() converts x from base n to base 10

// Pre: x is in the valid range

// n is in the valid range

// x is a valid base n number

// Post: The base 10 value of x has been returned

int convert(const int x, const short n);

#endif