Clinton Portis 211 Practically a Posting Shark

Line #6 of my code should be:

infile.seekg(i, ios::end);
Clinton Portis 211 Practically a Posting Shark

You seem to be interested in extracting only the last line of a text file, without having to read in the entire file.

If this is the case, I will provide a possible way to accomplish this.

You can set the 'get' pointer to the end of the document using seekg()

//Any offset provided as the first argument will be relative to the end of the file
infile.seekg (0, ios::end);

Work your way backwards until at such time you have reached the beginning of a line.. but how do you know when you are at the beginning? Based on your example file, a beginning of a line starts with a capital letter:

int i=0;
char c = '\0';
string sentence;

do{
     seekg(i, ios::end);
     c = infile.peek();
     i++;
     }while(c >= 'A' && c <= 'Z');

//Extract last line of file
getline(infile, sentence);

The above code is untested, uncompiled, and may contain small easy to fix errors. It is intended as one possible solution out of many possible for a given task.

Clinton Portis 211 Practically a Posting Shark

Important to know is that this file also only can consist of one line.

3 lines in a file:

Do you people not speak english as a native language... or enjoy confusing the rest of the world.

Here is an important excerpt from, "How to ask questions the smart way"

Write in clear, grammatical, correctly-spelled language
We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.

So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal — in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.

Spell, punctuate, and capitalize correctly. Don't confuse “its” with “it's”, “loose” with “lose”, or “discrete” with “discreet”. Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)

More generally, if you write like a semi-literate boob you will very likely be ignored. So don't use instant-messaging …

Clinton Portis 211 Practically a Posting Shark

Do you mean like this?

str1 += str2;
str1 += str3;
str1 += str4;
str1 += str5;

cout << str1;
Clinton Portis 211 Practically a Posting Shark

How can I check whether my code has memory leak or not?

  • objects allocated memory using 'new' must be deleted.
  • anytime you access an array out of bounds
  • anytime you try to dereferrence a NULL pointer.
  • anytime you leave a dangling pointer, for example:
int* a, b, c;

a = new int;
b = a;
c = a;
delete a;

//What are b and c pointing to..??!?  NOTHING!

This is all I can think of for now as far as memory leakage.

Clinton Portis 211 Practically a Posting Shark

By doing this, you have established a direct relationship between the two arrays:

//We can assume that 'votes[3]' corrosponds to 'candidates[3]', for example.
if ( inFile >> candidates[i] >> votes[i] )

So all you really need to do is extract the largest value from the votes[] array:

int index = 0;
int max = 0;

for(int i=0; i<6; i++)
{
     if(votes[i] > max)
     {
          max = votes[i];
          index = i;         
     }
}

cout << "The winner is " << candidates[index] << " with a winning vote count of " << votes[index];
Clinton Portis 211 Practically a Posting Shark
pToMax = &arr[0];

//should be
pToMax = &arr;
Clinton Portis 211 Practically a Posting Shark

I'm not sure what you are asking for, but I think you seem to be interested in preserving your white spaces. Try using getline():

string line[50];
int pos = 0;
int i=0;

while(getline(datoteka, line[i]))
{
     //Go back to the start of the line so you can extract data based on white spaces
     curr_pos = datoteka.tellg();
     char_count = gcount();
     datoteka.seekg(curr_pos - char_count);

     //Now you don't have to parse line[], just read the same line in again
     datoteka >> studenti[i].naziv_student >> studenti[i].visina;
     
    i++;
}

So now you have 'string line[]' which contains all the lines of the file with white spaces preserved.

This code is untested, uncompiled, and may contain small easy to fix errors (specifically, I am concerned about 'off by one' errors associated with my seekg() 'get pointer' placement.)

Clinton Portis 211 Practically a Posting Shark

it will say "scout arrived at 100,200"

After reviewing your loop, this seems to be the correct output in order to establish the terminating condition of your loop.. where toX == currentX AND toY == currentY... which will occur when toX becomes 100 (which is the initialized value of currentX) and toY becomes 200 (which is the initialized value of currentY)

Clinton Portis 211 Practically a Posting Shark

You are right on brother.

One suggestion: whenever you see a self re-assignment, you should have "compound operator" runnin' through your noggin'

y = y + 1;

//is the same thing as

y += 1;  //The += operator signifies "accumulation"

It's such a common task to re-assign a value to the original variable, that c++ made these compound operators available to you:

y = y / x;     y /= x;
y = y * x;     y *= x;
y = y - x;     y -= x;
y = y + x;     y += x;
y = y % x;     y %= x;

for (i = 0; i<=6;  i+=3)
for (j = 0; j<=15; j+=5)
kvprajapati commented: helpful! +6
Clinton Portis 211 Practically a Posting Shark

3*-4. Any ideas around this?

In the evaluation of polynomial expressions, it is safe to treat all " - " minus signs as preceding negative numbers (it is safe to assume there is no subtraction). The only special case one must consider is the case of the double negative, wich can be easily tested for.

Example:

-3x^2-4x = -5

Can trasnlate to:

Negative Three x squared plus negative four x = negative 5

Notice that there is no "subraction" involved with the evaluation of polynomials. With the exception of the double negative, you can safely assume all minus signs are only to identify negative values.

If your program supports only the basic math operations (addition, subraction, multiplication and division) between your polynomial terms, then all you really have to identify is * multiplication and / division... everything else is addition.

Clinton Portis 211 Practically a Posting Shark

Re: The last suggestion you made of making a Student object with 100 objects. This cannot be done as the user has to tell me how many students are on the roster. I have already have this created dynamically so that can be taken care of. Your suggestion of the default constructor did work for me though. This is the type of simple stuff I overlook.

I am aware of this.. I was just trying to demonstrate how you could create a bunch of objects of a certain class and know that all those objects have been initialized via the class default contructor.

Clinton Portis 211 Practically a Posting Shark

What you are suggesting is very possible, just change the desired function to accept a char parameter. Then at some point, you can use if/else logic based on that char argument to determine what type of problem ye' wish to produce.

Clinton Portis 211 Practically a Posting Shark

- BOTH HEADER FILES AND RELATED FUNCTIONS: I changed over my char arrays to strings (the project calls for maximums of characters). How do I easily change these over?

This doesn't seem like it would be that big of a deal. Change the header from <cstring> to <string>. Anytime you want to compare string objects use == instead of strcmp(), anytime you want to assign stuff to your string, use the assignment operator = instead of strcpy(), anytime you want to add to a string, use += instead of strcat(), etc, etc.

- ROSTERAPP.CPP: in displayStudent I have a comment for the loop if the entered number is found, but sometimes I get a FC. What am I doing wrong?

The success of this test depends on getID() to return non-zero "TRUE" if studentID exists, or return 0 "FALSE" if studentID has not been populated:

if (stu[id].getID() == false) //WORKING, but not the way it should... causes an FC error

As of right now, whenever a 'Student' object is created, none of the private variables are ever initialized.. so even if you create a new 'student' object, there is no guarantee that studentID will be zero (false), even though it has not been assigned anything. To make sure studentID is zero whenever new 'student' objects are created, we will make a simple default constructor. This is a function that will automatically get called every time a new 'student' object is created. We can use this feature to initialize …

Clinton Portis 211 Practically a Posting Shark

and then could NOT figure out how to change the parameters of my doOneSet function to do addition, subtraction and multiplication

There are many ways to go about this. Since you seem interested in changing the parameter list of your doOneSet() function... maybe we could do something like this (ok, I changed the parameter list of your doOneProblem() function instead.. it was easier for me)

void doOneSet()
{
     //simple loop will call the doOneProblem() function 5 times
     //instead of having to write out each individual function call
     for(int i=0; i<5; i++)
     {
      //Here we will supply a random number:  0,1 or 2
      //we'll make 0 = add, 1 = subtract, and 2 = multiply       
      doOneProblem(rand%3);    
     } 
}

Now when you get down to calcCorrectAnswer(), you could have something like this:

void calcCorrectAnswer(int &result, int &userNum1, int& operation)
{

     int num1, num2;

     switch(operation)
     {
          //addition
          case 0:  cout << num1 << " + " << num2 << " = ";
                   cin >> userNum1;
                   result = num1 + num2;
                   break;
          //subraction
          case 1:  cout << num1 << " - " << num2 << " = "; 
                   cin >> userNum1;
                   result = num1 - num2;
                   break;
          //multiplication
          case 2:  cout << num1 << " * " << num2 << " = ";
                   cin >> userNum1;
                   result = num1 * num2;
                   break;

          default:  cout << "Error..!";
     }
    
     checkAnswer(result, userNum1);
}

Even if this isn't exactly what you want, feel free to modify it as you like.. it's mainly here just to give …

Clinton Portis 211 Practically a Posting Shark

Well, it certainly looks like you are on the right track.. well stated question and lots of code which shows effort on your part.

You've created all the necessary objects with the required attributes and functions. You've created the dynamic arrays of these objects as per the requirement. Your menu makes effective use of the switch/case structure; each case calling a specific function. Your code is self documenting and easy to follow. You effectively use the 'seperate compilation' by segregating your code into various header files and .cpp function definitions.

Let us know if you have any specific problems. I looked at your code for setting the student's name and didn't see any problems, maybe someone else will see it. (don't have a compiler on me' old laptop so I can't debug)

You are doing a lot of things right here.. have you taken a programming class before.??

Clinton Portis 211 Practically a Posting Shark

I think your mind was still focused on that Halloween candy. :)

Clinton Portis 211 Practically a Posting Shark

you could probably do something like this:

int total = 0;

for(int counter=0; counter < i; counter++)
{
     total += product[counter].price;
}

cout << "Total goods sold is:  " << total;

Good looking well coded program btw. The only critique I have is that I would probably use a struct over a class, mainly because struct access is automatically made 'public' whereas with classes you have to use an extra line of code to change access to public.

Also, one mistake here:

}while(answer == 'y' || answer == 'Y' && answer !='N'&&'n');

//should be
}while((answer == 'y' || answer == 'Y') && (answer != 'N' || answer !='n'));

Although if you test for Y, you know your only other option would be N, so why even test for N...

Also, line #57 does not need to exist, because if you fall through the do/while loop, you can assume that the user no longer wants to input data and you can just continue with the rest of the program.

Clinton Portis 211 Practically a Posting Shark

you can easily perform a test on an entire range of values:

//If 'x' is greater than or equal to 1 AND 'x' is less than or equal to 380
if(x >= 1 && x <= 380)
{
     //Do amazing things
}
Clinton Portis 211 Practically a Posting Shark

this seems to work, I'll try it and let you know the results, but now its Halloween!!

Trick-or-Code (I think we all know the obvious answer to this question...)

Clinton Portis 211 Practically a Posting Shark

I need the DeAnza, CA, and FL to be already in an array without the user input.

Ok, I think we are narrowing this down here...

Just try something like this:

station[0].StationDesignation = "DeAnza, CA";
station[1].StationDesignation = "Naples, FL";
station[2].StationDesignation = "Buffalo, NY";
Clinton Portis 211 Practically a Posting Shark

I need the object (STATES) to be populated w/o the user input.

I am still not sure what you mean by this. The struct object has no attribute named 'states'.

In order to populate your structs, you will have to prompt the user for input.

I have provided a previous example of how you can provide the user a specific prompt for each state in which the related struct is to be populated.

If you would like to add additional information to your struct, such as the state, this attribute could possibly be loaded via comparison to an existing data database of information according to let's say, the station designation (for example, station id N70FX3 is located in california, and we could assign 'California' to a <string> attribute of your struct).

Please be very specific with your requests.

Clinton Portis 211 Practically a Posting Shark

Is there anyway to assign CA, FL, and NY to an array WITHOUT having to type them in?

I am not sure what you mean by this, but in my previous two examples, I prompted the user for input and then tested the input to make high/low determinations.

Edit: Ok, I think I know what you mean now.. you want to display specifcially which state you are entering instead of my generic prompts for user information.

Let's throw a little switch( ) action inside of our loop in order to customize our prompts for user input:

char ans;
int i=0; 

     do{      

               switch(i)
               {

                    case 1:  cout << "\nEnter data for CA:  ";     
                                 cin >> station[i].StationDesignation;  
                                 cin >> station[i].Temperature;
                                 break;    

                   case 2: cout << "\nEnter data for FL:  ";     
                               cin >> station[i].StationDesignation;   
                               cin >> station[i].Temperature;   
                               break;

                  case 3: cout << "\nEnter data for NY:  ";
                              cin >> station[i].StationDesignation;
                              cin >> station[i].Temperature;
                              break;

                 default:  cout << "\a\nInvalid Entry! ";
                               cin.get();
                               break;
     
          cout << "\nWould you like to enter another station?  (Y/N) ";     
          cin >> ans;      

          i++;      

}while(ans == 'Y' || ans == 'y');
Clinton Portis 211 Practically a Posting Shark

This is a common topic and very necessary for your CS academic career.

First, create your object:

struct WeatherStation{      

     string StationDesignation;     
     double Temperature;     
};

Now create a bunch of them. For your assignment, I think you only need 3 of them:

//creates array elements [0] thru [2]
     WeatherStation stations[3];

Now populate your 'station' objects:

char ans;
int i=0;

do{

     cout << "\nEnter Station Designation:  ";
     cin >> station[i].StationDesignation;

     cout << "\nEnter Station Temperature:  ";
     cin >> station[i].Temperature;

     cout << "\nWould you like to enter another station?  (Y/N) ";
     cin >> ans;

     i++;

     }while(ans == 'Y' || ans == 'y');

Now that your 3 'station' objects are populated, you can now sort the array. I'm in a fiesty mood today, so I'll use the swap( ) function from <algorithm>:

for(int i=0; i<2; i++)
{
     if(station[i].Temperature > station[i+1].Temperature)

          swap(&station[i+1], &station[i]);
}

Now your 3 'station' objects are sorted by their temperature attribute to ascending order (lowest to highest), so you know that station[0] will be the struct with the lowest temperature, and station[2] will be the struct with the highest temperature.

Also, I hope you can see how much code we have saved just by using an array data structure. It allows us to do the same things over and over via the use of loops and common array operations.

This is untested code and may contain easy to fix errors. If anyone knows of a better way to do this, please let us know.

Clinton Portis 211 Practically a Posting Shark

If you were using an array of structs, I would simply just tell you to sort the array based on the desired struct attribute, and simply pick off the struct at the begging and at the end of the array.

But since this is not the case, the best technique I can think of will be to make the high/low determination as soon as you accept user input (based on previous user input).

To do this, I am going to add a couple of flags to your struct. These flags will be initially set to FALSE, but will be set to TRUE anytime the struct qualifies for highest or lowest, and will be set back to FALSE whenever it no longer qualifies as the highest or lowest.

For this example, I will be using the 'temperature' attribute of the struct:

struct WeatherStation {

     bool highest;
     bool lowest;
     string StationDesignation;
     double Temperature;

     //Inline Constructor
     WeatherStation(){highest = FALSE;  lowest = FALSE;}
}CA, FL, NY;

string input;
int high=-200, low=200;

//Caleeforneeaah       
cout << "\nEnter California station designation:  ";
cin >> CA.StationDesignation;
cout >> "\nEnter California temperature:  ";
cin >> CA.Temperature;

if(CA.Temperature > high)
{
     high = CA.Temperature;
     CA.highest = TRUE;     
}
else if(CA.Temperature <low)
{
     low = CA.Temperature;
     CA.lowest = TRUE;
}

//Pablo honey, come to Florida...
cout << "\nEnter Florida station designation:  ";
cin >> FL.StationDesignation;
cout >> "\nEnter Florida temperature:  ";
cin >> FL.Temperature;

if(FL.Temperature > high)
{
     high = FL.Temperature;
     FL.highest = TRUE;
     CA.highest = FALSE: …
Clinton Portis 211 Practically a Posting Shark

how do i get the average of average?

add up all the tests and divide by the total number of tests.

Clinton Portis 211 Practically a Posting Shark

I have a feeling you may have place program output inside of a loop.

Let us see ye' code.

Clinton Portis 211 Practically a Posting Shark
int counter=0;

while(...)
{
     ...
     ...
     ...
    counter++
}

cout << "The while() loop executed " << counter << " times.";
Clinton Portis 211 Practically a Posting Shark

Error - Line #6, Should be:

bool deq_test(Str& deq1, Str& deq2){Return (deq1.a < deq2.a);}
Clinton Portis 211 Practically a Posting Shark

Let me offer this suggestion:

Using the sort() function from <algorithm> we find that there is an overloaded version of sort() that will allow us to supply our own custom-made 'test' function. Let's use this in order to specifically perform a test between two 'deques of structs'. We'll base our test on the 'int a' attribute of the struct:

Here are the two versions of sort():

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

template <class RandomAccessIterator, class Compare>
  void sort ( RandomAccessIterator first, RandomAccessIterator last, Compare comp };

The version we will be using is in green (above).

#include<algorithm>
#include<deque>
#include<ctime>
...
...
bool deq_test(Str& deq1, Str& deq2){Return (deq1.a < deq2.b);}
...
Str MyStr;
...
srand(time(NULL));
...
//Randomly populate ye' deque
for(int i=0; i<6; i++)
{
     MyStr.a = rand()%10;
     MyStr.b = rand()%10;

     deq.push_back(MyStr);
}
...
//Deque sorting goodness
sort(deq.begin(), deq.end(), deq_test);

//Now your deque is sorted according to the 'int a' Str struct attribute in ascending order.

The above code is untested and also I have never done this before but according to the instructions all this should work bueno.

Let me know how this works for ye' if you decide to use this.

Clinton Portis 211 Practically a Posting Shark

The requirements for this assignement approach an intermediate level of programming since we cannot use arrays or <string> class objects. Being that we are unable to use arrays, we cannot use 'c-strings' (char arrays). So what's left?

Our options include: STL containers and linked lists or just create a ton of singular char variables and hope we have enough for user input. Another option would be to write all the char variables to a file.

I'm open to suggestions, I think the method I used was probably the most primitive of options that I could think of.

Clinton Portis 211 Practically a Posting Shark

Try this and see if it works for ye'...

std::string& write();

std::string& test::write()
{	
          std::string *name = "HELLO";
          return name:
}
Clinton Portis 211 Practically a Posting Shark

line #24 should be: list->next = new node;

Clinton Portis 211 Practically a Posting Shark

can only use nested loops NO arrays or strings

I was kinda stumped at first until I came up with a linked-list of chars:

#include<iostream>
#include<cctype>
using namespace std;

struct node
{
     char letter;
     node *next;
};

int main()
{
     node *head_ptr = new node;
     node *list = head_ptr;
     int counter = 0;
     char input, ans;

     do{

               cout << "\nEnter a letter:  ";
               cin >> input;

               list->letter = toupper(input);      
               list->next = new list;
               list = list->next;

               counter++;

               cout << "\nWould ye' like to enter another letter? (Y/N) ";
               cin >> ans;                     

          }while(toupper(ans) == 'Y');

          list->next = NULL;
          list = head_ptr;

          int j=1;
          while(list)
          { 
               for(int i=0;  i<j && list; i++)
               {
                    cout << list->letter; 
                    list = list->next;
               }

               cout << endl;
               j++;
          }

         list = head_ptr;
         node temp;

          while(list)
          {
               temp = list;
               list = list->next;
               delete temp;               
          }         

return 0;
}

This code creates a 'linked-list' of nodes that contain space for 1 char per node. After the user is prompted to enter several letters, the list is traversed (starting from the head pointer) and displayed to the screen in a tree type manner.

This is untested code, so it might contain simple/easy to fix errors.

Clinton Portis 211 Practically a Posting Shark

oh, didn't see you need to round off to 2 decimal places....

setpricision is the way to go then.

Clinton Portis 211 Practically a Posting Shark

Good news.. the solution to your problem is wicked simple.

May I recommend the ceil() and floor() functions of the <cmath> library.

Clinton Portis 211 Practically a Posting Shark
#include <iostream>
using namespace std;

double calculatecharges(double);

int main(int argc, char *argv[])
{
     //Syntax Error Here
     //double hours; rate;

     double hours, rate;
     int x = 0;

     do 
     { 

          cout<<"Enter number of hours parked: ";
          cin>> hours;

          rate = calculatecharges(double hours);

          cout<< " your parking fee is :" << rate << endl;

          x++;

      }while(x < 4); 

     system("PAUSE");

return EXIT_SUCCESS;
}


//Syntax Error Here
//Only function prototypes get a semicolon
//double calculatecharges(double hours) ;

double calculatecharges(double hours) 
{
     double base_rate = 2;
     double long_rate = .50;
     double max_rate= 10;

     if (hours>3)

          rate=base_rate;

     else if (hours>3)

          rate=((hours-3)*long_rate + base_rate);

     else (hours>11)

          rate = max_rate;
}
Clinton Portis 211 Practically a Posting Shark

finding and storing the relevant line number the string was located at on the file in the token objects.

If I understand you correctly, you seem to be in need of keeping track of what line you are at whilst reading from a .txt file.

So, I will suggest a way to keep track of what line ye' are reading from.

It looks like you are >> streaming in single words at a time from the .txt file... I would suggest using the<string> class function called getline() instead, so you can keep a counter associated with how many times ye' have called getline() and thusly know which line ye' are on.

This is what you have:

while( inFile.peek() != EOF )
{

     inFile >> tokens[ tempx ].tokenString;

     tempx++;

}

Try changing to this:

int tempx = 0;

while(getline(infile, tokens[ tempx ].tokenString))
{    
     //Here 'tempx' can also be your "line counter"
     tempx++;
}

Now you have tempx as a line counter, refer to it as necessary to determine what line ye' are on.

But I bet you are asking yourself, "that's great clinton portis.. but now my token array contains entire lines instead of individual words."

So, to get around this, you can use <string> member functions to return individual words from your array (such as find(), find_first of(), and substr()). Or you can perform array operations on your token array to extract individual words. you could use strtok() (if …

Clinton Portis 211 Practically a Posting Shark
cout << "The total is: " << x;
Clinton Portis 211 Practically a Posting Shark

:D

Clinton Portis 211 Practically a Posting Shark
if (StatsChange == "Strength" or "strength" or "str" or "STR" or "Str")

should be:

if (StatsChange == "Strength" || StatsChange == "strength" || StatsChange== "str" || StatsChange== "STR" ||StatsChange== "Str")

I know, believe me I did the same thing when I first got into boolean logic.. because the way you do it (aside from the incorrect symbology) seems correct at first, and more code efficient. However, please realize that there are specific rules at play here; each expression is handled individually.

If only one variable exists, the boolean test will either return TRUE if not zero, and FALSE if zero. Example:

if(variable)
{
     //code 
}

In this instance, if 'variable' contains any value, it will test TRUE and will enter/execute the contents of the if() structure. Conversely, if 'variable' contains a zero, the boolean expression will test FALSE and will simply skip over the entire if() structure.

So like me, you are probably wondering how to avoid these huge multiple lines of logic. Here is one way I can think of:

string input = {"Strength", "strength", "str", "STR", "Str"};
bool match = FALSE:
int i=0;

do{
     if(StatsChange == input[i])
     {
          match = TRUE;
     }
}while(match == FALSE || i < 5);

Placing boolean tests inside of a loop could potentially eliminate several lines of logical testing.

Clinton Portis 211 Practically a Posting Shark

The most popular method of delay is to use the Sleep() function, a member of the <windows.h> library.

Clinton Portis 211 Practically a Posting Shark

Try this:

char letter = 32;
int counter = 0;

while (letter < 128)
{    
     cout << letter << ' ';

     counter++;

     if(counter == 16)
     {
         cout << endl;
         counter = 0;
     }

     letter++;     
}
Clinton Portis 211 Practically a Posting Shark

Luckily for you, the c++ standard provides you with the tools necessary to open, read, and write to files. You can use these tools by including the <fstream> library. Then you can create ifstream objects that will allow you to open and read from a file, and ofstream objects that will allow you to write to a file.

Here is a pretty decent tutorial for opening, reading and writing to text files using the <fstream> library: http://www.cplusplus.com/doc/tutorial/files/


So, you wish to open a file and examine it's contents in 5 character increments. Since we will not be writing to file, all we will need is a 'ifstream' object.

Probably the easiest method I can think of will involve opening a file, reading its entire contents into a single <string> object, and then performing the desired operations on that string.

I'm not sure what your data will look like, so I will have to make some assumptions with this code, but feel free to modify it as you like.

Here is the pseudo code for what I am about to demonstrate:

1. create an 'ifstream' object (derived from <fstream>)
2. attempt to open an existing .txt file.
3. perform error checking (check to see if file opened correctly)
4. read the entire .txt file into a single 'string' object.
5. perform desired operations on string object (in 5 char increments)
6. close the ifstream object

jbennet commented: good reply +21
Clinton Portis 211 Practically a Posting Shark

Look at your output table.... do you see anything in your code you could use as a counter? (hint: your days are numbered)

Clinton Portis 211 Practically a Posting Shark

one simple strategy, would be to pass the char array into your function as a reference.. therefore any manipulations you perform on the char array will affect it directly in memory.

algorithmically, reversing the array is simple. create a new dynamic temporary char array of equal length. copy first element to last element, copy first element+1 to last element-1, copy first element+2 to last element-2 etc. Then, copy the temp array back to the original array.

that's all there is to it.

Clinton Portis 211 Practically a Posting Shark

According to http://www.cplusplus.com/ref/iostream/istream/getline.html, the two acceptable forms of cin.getline() are:

istream& getline (char* s, streamsize n );
istream& getline (char* s, streamsize n, char delim );

Both versions expect a char pointer as the first argument.. not a string class object. Luckily, string class objects contain a method that will return a char pointer. Try this:

cin.getline(playerOne.c_str(), 21);

Edit: Ancient Dragon's post is the preferred method actually.

Clinton Portis 211 Practically a Posting Shark
else if (guess = num)

should be:

else if (guess == num)
Clinton Portis 211 Practically a Posting Shark

does she like younger men

Clinton Portis 211 Practically a Posting Shark

This is what I am thinking...

Your loop condition is based on a=1 and will increment while a < size()+1.

for(int a=1;a<(S.size()+1);a++)

But my guess is.. your linked list is "zero based".. much like how an array is.. which would account for why all other elements would be deleted.. except for your very first one.. which is, "node zero" or the head node..

try this and see what happens:

for(int [b]a=0[/b]; a<S.size()+1; a++)