Clinton Portis 211 Practically a Posting Shark

Ah, that makes sense. Adjust the code to account for the given day.

I would recommend dedicating a variable that will identify a call as either weekday or weekend. I would probably make this a bool type variable. For this example, I'll call make it bool is_weekend, set to false if it is a weekday call and set to true if it is a weekend call:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//identify call as a weekday or weekend call
if(chday == 'A' || chday == 'S')
{
     is_weekend = true;
}
else
{
     is_weekend = false;
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //weekday call
     if(!is_weekend)
     {
          //calculate reg. rate and apply 40% discount
          full_cost += (call_duration * .30) * .6;
     }
     //weekend call
     else
     {
          //calculate reg. rate and apply 60% discount
          full_cost += (call_duration * .30) * .4;
     }    
}

So on and so forth.

Clinton Portis 211 Practically a Posting Shark

Although I don't fully understand the assignment, I will attempt to throw some code your way to help get the gears spinnin' inside ye' head.

based on your current coding style, i would suggest simple if/else logic:

//all calls will be at least E1.50
full_cost = 1.5;

//adjust call duration
if(call_duration > 3)
{
     call_duration -= 3;  //3 minutes
}

//enforce 10hr. limit
if(call_duration > 597)
{
     call_duration = 597;  //10hr. limit (minus 3min. initial charge) converted to minutes
}

//make rate determinations (calls made between 11pm to 8am ending before 5pm)
if(call_start >= 2300 && call_start <= 0800 && call_end <= 1659)
{
     //calculate reg. rate and apply 40% discount
     full_cost += (call_duration * .30) * .6;
}

//for calls made before 8am lasting longer than 5pm
else if(call_start >= 2300 && call_start <= 0800 && call_end <= 2259)
{
     //calculate reg. rate, apply 40% up until 5pm
     full_cost += ((1659 - call_start) * .30) * .6;
     //then apply 60% discount after 5pm
     full_cost += ((1700 + call_end) * .30) * .4;
}

/* 
     and so on and so forth, accounting for all the different call scenarios, but not accounting for calls that exceed 10 hours.
*/

This is not complete code but it is at least something to get you started.


This does not make sense to me, because it says you apply a discount, but then it says to apply another discount.. quite confusing:

Before 8am 40% discount 60% discount
8am …

Clinton Portis 211 Practically a Posting Shark

Force total user compliance: (you call it error trapping)

do{

     //stuff
     //suff
     //and more stuff

     if(is user input correct?)
     {
          //Display error message
     }

}while(user input is incorrect);

To run your program multiple times, do this:

int main()
{
     char choice = '\0';

     do{
  
          //stuff
          //stuff
          //stuff

          cout << "\nWould ye' like to try again?  (Y/N): ";
          cin >> choice;

     }while(choice == 'y' || choice == 'Y');
 
     return 0;
}

Follow these simple topologies and ye' will be good to go.

jonsca commented: Mad rep for using the word "topology" in your post +2
Clinton Portis 211 Practically a Posting Shark

Your plus is almost done.. except you need to move the top 1/2 veritcal line and the bottom 1/2 vertical line off the left edge of the screen.

One way you can get the spaces you need, is to create an array of spaces:

int size = 0;

//Declare the array 
char spaces[80];

//Initialize the array to all spaces
for(int i=0; i<80; i++)
{
     spaces[i] = ' ';
}

cout << "Enter size of plus sign: ";
cin >> size;

//Put a null terminating delimiter in the space array so we will have the correct amount of padding
spaces[size/2] = '\0';

//Now you have a set number of spaces to use to pad your plus sign :)
 for(int i=0; i<number/2; i++)
{
     cout << spaces << symbol << endl;
}

Like I said before.. many ways to do this thing. Seems like you are pretty much done with ye' assignment. Let us know how it goes.

Clinton Portis 211 Practically a Posting Shark

You forgot to #include<iomanip>.

Clinton Portis 211 Practically a Posting Shark

You may need something like this:

bool is_vowel(char& test)
{
     switch(test)
     {
          case 'a':
          case 'e':
          case 'i':
          case 'o':
          case 'u':  return true;
          default :  return false;
     }
}
Clinton Portis 211 Practically a Posting Shark

...

Clinton Portis 211 Practically a Posting Shark

but then new value that is to be inserted has to be after the current_index and the function i have now places it before

i have no idea how to make that change

data[current_index+1] = entry;
Clinton Portis 211 Practically a Posting Shark

look at my previous post. the problem is in line #8. make the correction and let us know what you did to fix the problem.

Clinton Portis 211 Practically a Posting Shark

This project will require you to develop three C functions:

You are asking for C help in a C++ forum. You deserved to be weeded out of the natural order of the human species. I should do your assignment in c++ and let you turn it in.

Ancient Dragon commented: Good idea :) +26
Clinton Portis 211 Practically a Posting Shark
//Provides ability to write to the dos console (cin/cout)
#include<iostream>

using namespace std;

int main()
{
     int input = 0; 

     cout << "Enter t or f: ";
     cin >> input;

     do{

          if(input == 't') 
          {
               cout << "True";
          }
          else if(input == 'f') 
          {
               cout << "False";
          }
          else
          {
               cout << "Incorrect entry.  Try again. \n";
          }
     
     }while(input != 't' && input != 'f');

     return 0;
}
WaltP commented: You need to STOP posting code for people. Their job is to write the code. You job is to stop trying to impress everyone with your coding prowess. -2
Clinton Portis 211 Practically a Posting Shark

As stated by thomas_naveen, you have a classic eof() problem which will need to be remedied in order for your program to work.


I can't understand why it says its out of range when the pos and length I supplied is valid.

The position of your first white space resides in myArr[0], not myArr[1].

//you have
myArray[count].address=line.substr((myArr[1]+1), (myArr[2]-(myArr[1]+1)));

//when it should be:
myArray[count].address=line.substr((myArr[0]+1), (myArr[1]-(myArr[0]+1)));

There were a couple of other minor issues. In summary, this is what your program should look like thus far:

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

class Employee
{
public:
	string name;
	string address;
	string  age;
	string salary;
};

void fill_file()
{
	ofstream myFile("EmployeeDetails.txt");
	myFile << "Emp1 P_louis 18 20,000\n";
	myFile << "Emp2 P_louis 18 20,000\n";
	myFile << "Emp3 P_louis 18 20,000\n";
	myFile << "Emp4 P_louis 18 20,000\n";
	myFile << "Emp5 P_louis 18 20,000\n";
	myFile << "Emp6 P_louis 18 20,000\n";
	myFile << "Emp7 P_louis 18 20,000\n";
	myFile << "Emp8 P_louis 18 20,000\n";
	myFile << "Emp9 P_louis 18 20,000\n";
	myFile << "Emp10 P_louis 18 20,000\n";
	myFile << "Emp11 P_louis 18 20,000\n";
	myFile << "Emp12 P_louis 18 20,000\n";
	myFile << "Emp13 P_louis 18 20,000\n";
	myFile << "Emp14 P_louis 18 20,000\n";
	myFile << "Emp15 P_louis 18 20,000\n";
	myFile << "Emp16 P_louis 18 20,000\n";
	myFile << "Emp17 P_louis 18 20,000\n";
	myFile << "Emp18 P_louis 18 20,000\n";
	myFile << "Emp19 P_louis 18 20,000\n";
	myFile << "Emp20 P_louis 18 20,000\n";
	myFile.close();
}


int main()
{
	int x,y;
	int len;
	int i;
	int count=0;
	int pos;
	int myArr[3]; …
Clinton Portis 211 Practically a Posting Shark

Try looking it up.

Ok, I'll do the work for you:
http://www.cplusplus.com/reference/algorithm/random_shuffle/

template <class RandomAccessIterator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last );

template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& rand );

Rearrange elements in range randomly
Rearranges the elements in the range [first,last) randomly.

The function swaps the value of each element with that of some other randomly chosen element. When provided, the function rand chooses which element.

template <class RandomAccessIterator, class RandomNumberGenerator>
void random_shuffle ( RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& rand )

{
  iterator_traits<RandomAccessIterator>::difference_type i, n;
  n = (last-first);
  for (i=2; i<n; ++i) swap (first[i],first[rand(i)]);
}

Parameters

first, last
Forward iterators to the initial and final positions of the sequence to be shuffled. The range used is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
rand
Pointer to unary function taking one argument and returning a value, both of the appropriate difference type (generally ptrdiff_t). The function shall return a value between zero and its argument (lower than this).

// random_shuffle example
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;

// random generator function:
ptrdiff_t myrandom (ptrdiff_t i) { return rand()%i;}

// pointer object to it:
ptrdiff_t (*p_myrandom)(ptrdiff_t) = myrandom;

int main () {
  srand ( unsigned ( time (NULL) ) );
  vector<int> myvector;
  vector<int>::iterator it;

  // …
Clinton Portis 211 Practically a Posting Shark

"vector subscript out of range"

Just based on that piece of information alone, I bet you are attempting to access a vector element that is larger than vector.size()

vector<int> v;

v.push_back(1);
v.push_back(2);
v.push_back(3);

//No bueno...  only elements 0,1, and 2 are currently populated:
cout << v[3];   //Access out of bounds
Clinton Portis 211 Practically a Posting Shark

Here is a freebee for ye':

c) create a date constructor that reads the system date using the standard library functions of the <ctime> header and sets the Date members

class Date
{
     public:

     //Default constructor
     Date();

     private:

     //Date members
     struct tm* timeinfo;
     time_t rawtime;
     int day;
     int month;
     int year;    
};
Date::Date()
{
     time(&rawtime);
     timeinfo = localtime(&rawtime);

     day = timeinfo->tm_mday;
     month =  timeinfo->tm_mon;
     year =  timeinfo->tm_year + 1900;
}

http://www.cplusplus.com/reference/clibrary/ctime/

Clinton Portis 211 Practically a Posting Shark

but the verticle line must correspond with the number the user chooses

A loop is an excellent way to control dos console output based on user input. Additionally, use of setw() will allow you to scale the plus sign based on user specified dimensions.

Compile, run, and experiment with the following code:

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{
     int size = 0;

     cout << "Enter size of plus sign: ";
     cin >> size;

     //Draw vertical line (top half)
     for(int i=0; i<size/2; i++)
     {
          cout << setw(size/2) << '*'  << endl;
     }

     //Now draw the horizontal line
     for(int i=0; i<size; i++)
     {
          cout << '*';
     }

     //Now draw the bottom 1/2 of the plus

     return 0;
}
Clinton Portis 211 Practically a Posting Shark

There are many ways to do the plus sign...

If you chose to use the setw() function, be sure to #include<iomanip>

You could make a char[] array of spaces (c-string)

If you chose not to use setw(), you could use a string literal consisting of a bunch of spaces....

Or you can make a string object and assign it a bunch of spaces.

You could use nested loops.. but in this case, for me personally, I would focus on constructing each part of the plus sign individually:

#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;

int main()
{

     //using a null-terminated c-string
     char spaces[10] = {'','','','','','','','','','\0'};

     //Build the vertial line (top half)
     for(int i=0; i<10; i++)
     {
          cout << spaces << '*' << endl;
     }

     //Now draw the horizontal line
     cout << "**********";

     //Draw the bottom half of plus
     //Just do the same thing as the top half

     return 0;
}

I know this isn't exactly what ye' are looking for, but it should give you an idea of just one way (out of infinite possibilites) of how to draw this thing...

You have many ways to do the same thing.. you could use multiple loops, you could use a nested loop.. you could use no loops at all. So how do you know what to use? Use what you think would be the easiest and most effective methods to accomplish the goals of your assignment.

Clinton Portis 211 Practically a Posting Shark

In your example:

(5 + 6(3+2) - 2(8*2) +1)

Moving from left-to-right, in order to find a valid parenthesized pair, you have to find any condition where a ')' is found after traversing the most recent '('

From left-to-right, anytime multiple '(' are detected, the previous '(' position should be discarded.. only keep track of the position of the most current '('

Upon detection of the first ')', you now have the position of a valid parenthesized term. The parenthesis that make this term need to be discarded as candidates from future searches.

Clinton Portis 211 Practically a Posting Shark

Line #12: Initialize 'c' to 9 instead of 10.

Line #32: Initilize 'g' to 9 instead of 10.

Clinton Portis 211 Practically a Posting Shark

begone with ye' C code.

Clinton Portis 211 Practically a Posting Shark

Your program should prompt the user to enter the number of rows and columns in the 2-d grid.

since you will have the user define the dimensions of your 2d array, you should use a dynamic 2d array:

int rows = 0;
int cols = 0;

cout << "Enter rows: ";
cin >> rows;
 
cout << "Enter cols: ";
cin >> cols;

//Dynamic 2D array
//1st dimension memory allocation:
char** grid = new char*[rows];

for(int i=0; i<rows; i++)
{
     //2nd dimension memory allocation:
     grid[i] = new char[cols];
}

//Now you have grid[][] of dimensions determined by the user

You can either statically use arrays of an arbitrary amount, or you can dynamically allocate array memory.. but you can't do both:

int rows = 0;
int cols = 0;

cout << "Enter rows: ";
cin >> rows;
 
cout << "Enter cols: ";
cin >> cols;

//No bueno   :'(
grid[rows][cols];
Clinton Portis 211 Practically a Posting Shark
  • create 2 objects of type 'ifstream'
  • open the two files
  • read in the desired stuff to a container of your choice (usually string objects or vectors)
  • compare the two strings
string word1, word2;
ifstream infile1, infile2;

infile1.open("doc1.txt");
infile2.open("doc2.txt");

word1 << infile1;
word2 << infile2;

if(word1 == word2)
    cout << "Same";

else
     cout << "Different";
Clinton Portis 211 Practically a Posting Shark

we need the code.

Clinton Portis 211 Practically a Posting Shark

At first glance, your stuff looks good...

Have you tried #include<iostream> ??

Clinton Portis 211 Practically a Posting Shark

Although I'm not familiar with Allegro, I am almost certain your game uses a single bitblt() (or "blit()" in Allegro I think) to constantly update the screen.. you'll need to learn how to "double buffer" your screen in order to gain that fluid 'non-flickering' update that ye' desire.

Although this is a win32 animation tutorial, glance down at the section on 'Double Buffering' and you'll at least get an idea of what needs to be done. The concept seems quite simple and could probably be implemented in your Allegro application with great ease:

http://www.winprog.org/tutorial/animation.html

Have fun & good luck with the game !

Clinton Portis 211 Practically a Posting Shark

Here is just a very simplified taste o' win32 printer basics.
(based on pg. #633 - 637, "Programming Windows, 5th Edition. Petzold.) Simplified and translasted to c++ by me.

This code is based on a flowchart describing typical print routine (pg. #639, Petzold):

  • SetAbortDoc
  • StartDoc
  • StartPage
  • Print 1 page
  • EndPage
  • User abort Printing?
  • Document Completed?
  • EndDoc

For simplicity I omitted the abort procedure:

int yChar = 0;
int iCharsPerLine = 0;
int iTotalPages = 0;

PTSTR ptstrBuffer;
TEXTMETRIC tm;
DOCINFO di;
PRINTDLG pd;

//Set Doc Info 
di = {sizeof(DOCINFO), TEXT("My Print App, yo'.")};

//Set commong print dialog box attributes
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd;
pd.hDevMode = NULL;
pd.hDevNames = NULL:
pd.hDC = NULL:
pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_NOSELECTION;
pd.nFromPage = 0;
pd.nToPage = 0;
pd.nMinPage = 0;
pd.nMaxPage = 0;
pd.nCopies = 1;
pd.hInstance = NULL;
pd.iCustData = 0;
pd.lpfnPrintHook = NULL;
pd.lpfnSetupHook = NULL;
pd.lpfnPrintTemplateName = NULL;
pd.lpfnSetupTemplateName = NULL:
pd.hPrintTemplate = NULL;
pd. hSetupTemplate = NULL;

//Display Standard Print Dialog 
PrntDlg(&pd);

//Calculate necessary metrics for file
GetTextMetrics(pd.hDC, &tm);
yChar = tm.tmHeight + tm. tmExternalLeading;
iCharsPerLine = GetDeviceCaps(pd.hDC, HORZRES) / tm.tmAveCharWidth;
iLnesPerPage = GetDeviceCaps(pd.hDC, VERTRES) / yChar;
iTotalPages = (iTotalLines + iLinesPerPage - 1) / iLinesPerPage;

//Allocate a buffer for each line of text
ptstrBuffer = new TCHAR[iCharsPerLine + 1];


// **Here is where the real printing work begins**

//Start Document
StartDoc(pd.hDC, &di);

//Print pages
for(int i=0; i<pd.nCopies; i++)
{
     //Start Page
     if(StartPage(pd.hDC) < 0)
     {
          break;
     } …
Clinton Portis 211 Practically a Posting Shark
#include iostream
using namespace std;

int funcReturn(int& index);

int main()
{
     for(int i=0; i<3; i++)
     {
          cout << funcReturn(i);
     }

     return 0;
}

int funReturn(int& index)
{
     int a[3] = {33, 44, 55};
    
     return a[index];
}
Clinton Portis 211 Practically a Posting Shark

It's 1:12am and I am wicked tired, but here is a link that will give you an overview of what you are about to get into if you choose to pursue the win32 api route:

http://en.allexperts.com/q/C-1040/Setting-Printer.htm

Other possible solutions may involve usb level programming (which I know just enough to be dangerous)

If you decide to go with win32 api, I'll break out the win32 bible tomorrow and come up with a simple code to print something.

Clinton Portis 211 Practically a Posting Shark

If the network printer is selected as the default device, why not just print normally?

Printing (as far as I know using win32 api, which I know you don't want to use) involves the evokation of a standard dialogue box in which the use gets to choose the printing device as well as many other attributes.

Clinton Portis 211 Practically a Posting Shark
for(int i=0; i<10; i++)
{
     cout << i;
}

for(int i=10; i>0; i--)
{
     cout << i; 
}
Clinton Portis 211 Practically a Posting Shark

Being able to use loops effectively is an essential and very powerful programming technique.

Use a loop anytime you want to do a bunch of the same stuff over and over.

I can execute a million instructions with just a few lines of code:

//Print all numbers from 0 to 1,000,000
for(long int i=0; i<1000001; i++)
{
     cout << i << ' ';
}

But what if I only want let's say, only 5 numbers per line....

//Outter loop
for(long int i=0; i<200000; i++)
{
     //Inner loop
     for(int j=0; j<5; i++, j++)
     {
          cout << i << ' ';
     }
     
     cout << endl;
}

You can do pretty much anything you want to do with loops.. your imagination is your only limitation. Get down with loops and you will have a much more enjoyable time as a CS student.

Clinton Portis 211 Practically a Posting Shark

http://www.cplusplus.com/reference/string/string/find_first_of/

bool is_single_vowel(string word)
{
     //All words contain at least 1 vowel; find it:
     size_t found = word.find_first_of("aeiouAEIOU");

     //Handle Special Case:  If no vowel was detected, word must be using single 'y' as a vowel:
     if(found == string::npos)

          return true;

     //Attempt to find any occurance of a second vowel
     found = word.find_first_of("aeiouAEIOU", found+1);

     //If no second vowel was detected, return TRUE
     if(found == string::npos)

          return true;

     //Else word contains two or more vowels
     else

          return false;
}

Try upgrading your test condition in Line #28 to this:

if (word.size () > longest_word.size () && is_single_vowel(word))
Clinton Portis 211 Practically a Posting Shark

I'm not sure why you are getting that.. it may be due to incorrect switch syntax.. try using another variable name other than i.

You are on the right track btw. You need to wrap your head around basic loop operations before even picking up your assignment.

Here's a freebe for ye':

//draw a square (just one way out of infinite possibilities)

//draw top
for(int i=0; i<10; i++)
{
     cout << '*';
}

//draw sides
for(int i=0; i<10; i++)
{
     cout << endl << '*' << "         " << '*';
}

//draw bottom
for(int i=0; i<10; i++)
{
     cout << '*';
}

tips:

  • don't overcomplicate your switch, keep it simple. Use functions calls or small blocks of code.
  • When using nested loops, be sure to indent and always use braces.

Good attempt at experimental code you got btw.. good learning process taking place. Sometimes you just gotta get in there and try stuff and see what happens.

Clinton Portis 211 Practically a Posting Shark

try this:

string filename;

cin >> filename;

filename += ".dat";

outFile.open(filename.c_str());
Clinton Portis 211 Practically a Posting Shark

Run and compile this little program. Go through it line by line. Proceed no further until you understand the basics of using a simple loop. Then when you are comfortable, do experimentation with changing the loop conditions and loop contents to make it do new and exciting things:

#include iostream
using namespace std;

int main()
{
     int lines = 0;
     char c = '\0';

     cout << "Enter number of lines: ";
     cin >> lines;

     cout << "\nEnter a character: ";
     cin >> c;

     //Learn to use simple loops
     //Don't be afraid to try new things here
     // (make it loop backwards for example)
     //Your imagination is the only limitation.
     for(int i=1; i<lines; i++)
     {
          for(int j=0; j<i; j++)
          {
               cout << c;
          }
     
          cout << endl;
     }

return 0;
}
Clinton Portis 211 Practically a Posting Shark

IS THERE A BETTER WAY TO DO IT?

Look at lines #20 through #28 in my previous post for a better way to do this.

Yes, you will have to learn to use nested loops, which I believe is the goal of your assignment.

As for the overall design of your assignment, the important pieces of your program could look like this:

display_menu();

cout << "Enter shape to draw: ";
cin >> shape_selection;

cout << "Enter character to use to draw shape: ";
cin >> char_selection;

cout << "Enter odd number of lines to draw: ";
cin >> lines;

switch(shape_selection)
{
     case 1:  draw_tri(char_selection, lines);
     break;
     case 2:  draw_upsidedown_tri(char_selection, lines);
     break;
     case 3:  draw_rectange(char_selection, lines);
     break;
     case 4:  draw_plus_sign(char_selection, lines);
     break;
     default:  menu_error();
}

//Function definitions
void draw_tri(int char_selection, int lines)
{
     //Use a nested loop to draw a triangle, line at a time, top to bottom
     //Copy and paste the triangle algorithm from my previous post
     //No thinking required.
}

void draw_upsidedown_tri(char_selection, lines)
{
     //Use a nested loop to draw an upside-down triangle
     //Refer to my previous post for a triangle drawing algorithm
     //Alter the loop conditions to draw the triangle upside-down.
}

void draw_rectangle(char_selection, lines)
{
     //draw top of rectangle
     //Using a loop, draw left side, bunch of spaces, then draw right side.  Newline each loop iteration.
     //draw bottom of rectangle
}

void draw_plus_sign(char_selection, lines)
{
     //use a loop to draw vertical top half of plus, newline each loop iteration.
     //draw the horizontal row of …
Clinton Portis 211 Practically a Posting Shark

When testing for primes, you only need to test half the range:

bool is_prime = true;

cout << "Enter a numeral: ";
cin >> number;

if(number == 1 || number == 3)
{
     cout << "Number is prime.";
     exit(0);
}

for(int i=2; i<number/2; i++)
{
     //If there is any case of no remainder, then number is not prime
     if(number%i)
     {
          is_prime = false;
          break;
     }
}

if(is_prime)

     cout << number << " is a prime number. ";

else 

     cout << number << " is not a prime number. ";

There might be easier ways to do this.. this is just something I came up with off the top of me' head.

Clinton Portis 211 Practically a Posting Shark

You are losing the fact that there is an array. All the function knows is a pointer was passed in. It has no idea how many locations are associated with the pointer. You need to also pass the size into the function.

void myfunction(int array[], int array_size)
{
    //stuff
}
Clinton Portis 211 Practically a Posting Shark

Here is an in-depth discussion I googled concerning the dangers of using sizeof(array)/sizeof(arraytype) in order to get current length of an array:

http://www.gamedev.net/community/forums/topic.asp?topic_id=345898

Some alternatives to consider:

  • Dedicate a 'size' variable to hold number of entries made into an array.
  • Use null-terminated c-strings; get array length using strlen().
  • Use an STL container such as String or Vector, use a size() member function to return string length.
Clinton Portis 211 Practically a Posting Shark

I phrased my previous recommendation carefully by stating, "...initialize all variables to appropropriate game start values" which may or may not be zero. The var I am speaking of specifically is int sticks.

Clinton Portis 211 Practically a Posting Shark

Winsock is very popular, easy to use, and is a very good skill to have on the ol' resume. Companies will love you.

Clinton Portis 211 Practically a Posting Shark

In line #8 you have a bunch of uninitialized variables which may be causing unpredictable behavior. Try initializing these variables to correct game starting values.

Clinton Portis 211 Practically a Posting Shark

The problems I'm having now are that the user is only allowed to input a number of sticks to remove once

I believe this problem may be due to an incorrect (and easily fixable) test condition in line #32.

Also, the computer is not generating a number 1 through 4 to remove like it should be.

Line #70 is currently generating a pseudo-random number between 0 and 3. Try this:

comp_choice = (rand()%4) + 1;
Clinton Portis 211 Practically a Posting Shark

It seems to me that making a function call to determine who the current player is in a game of tic-tac-toe is overkill. It is safe to assume that there will always be two players. It is also safe to assume that if player 1 went, then it will be player 2's turn and vice-versa.

However, if ye' wish to make a function call to determine the current state of playerness, try making a function that will return the current player:

bool getplayer()
{
     return is_player_1;
}

It is likely that your win() function is being adversly affected by the incorrect drawing of X's and O's to the game board (board[][]). Upon cleanup of your getplayer() function I believe you will see better results.

Clinton Portis 211 Practically a Posting Shark

Your 'function-local' variable named TotalMPG we be created and thusly destroyed with every call of the MPG() function.

Try creating a class variable that will retain the odometer reading.

Clinton Portis 211 Practically a Posting Shark

it is possible. i did not include my usual disclaimer: "The code provided is uncompiled, untested and may contain simple, easy to fix errors." The theory is sound. I did most of the thinking for you. Please make at least some sort of attempt to resolve any simple syntax errors. Any effort on your part = good.

Clinton Portis 211 Practically a Posting Shark

You are attempting to implement the answer using a linear method. Try using a nested loop and I think you'll have the results ye' be looking for:

int lines = 0;
char c = '\0';

//Prompt for user input
do{
     cout << "\nEnter an odd number of lines of triangle to be drawn: ";
     cin >> lines;

     //Test user input
     if(! lines%2)
     {
          cout << "\n\aNumber entered is even.  Please enter an odd number.";
     }
}while(! lines%2);

cout << "\nEnter chararcter to be used to draw triangle: ";
cin >> c;

//Draw ye' precious triangle
for(int i=0; i<lines; i++)
{
     for(int j=0; j<i; j++)
     {
          cout << c;
     }
     
     cout << endl;
}
jonsca commented: Arg matey, Cap'n Portis is back +2
Clinton Portis 211 Practically a Posting Shark

Useful tips:

you can consolidate lines 13 through 33, and eliminate lines 35 through 44 by doing this:

// Initializing the eight choices.
	int iChoice1 = (rand() % 8) + 1;
	int iChoice2 = (rand() % 8) + 1;
	int iChoice3 = (rand() % 8) + 1;
	int iChoice4 = (rand() % 8) + 1;
	int iChoice5 = (rand() % 8) + 1;
	int iChoice6 = (rand() % 8) + 1;
	int iChoice7 = (rand() % 8) + 1;
	int iChoice8 = (rand() % 8) + 1;

Furthermore, keeping your choices in array format would continue to simplify your code:

int choices[8];

for(int i=0; i<8; i++)
{
     choices[i] = (rand()%8) + 1;
}
Clinton Portis 211 Practically a Posting Shark
#include iostream
using namespace std;

main()
{
     cout << "Q:  How many hookers does it take to screw in a light bulb?";
     cout << "\nA:  Go ask your mom.";
     return 0;
}
iamthwee commented: BRAVO! +11
Ancient Dragon commented: :) +26
Clinton Portis 211 Practically a Posting Shark

You need to refine your question before we go all out w/ a bunch of code to give you what may or may not be the correct answer.

You unclear in some aspects of your question; for example, you state that you require an 'odd number' input from the user, but then later give 'rectangle' and 'plus sign' as possible shapes that could be derived from user input (which have even number sides).

Additionally, when the user enters an odd number, does this input correspond to the number of sides of the shape, or the number of characters needed per side to create a triangle?