Thread: For Loop Issues

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    For Loop Issues

    Problem:
    I am trying to code a sample textbook program that will take a string consisting of a first and last name that are separated by a space, (ie."John Doe"), and then reorder them so as to read: "Doe, John". I am using the below stated pseudocode out of the textbook. Obviously there is more pseudocode than what I list here; however I'm pretty sure that the rest of my code is right. All of my internal testing works fine up to this point. That is, all of my arrays and variables test print just fine up to this point.

    I think that my problem lies in my FOR statement. The current code that I am using, just prints out ascii characters on output. I am a newbie and trying to get my brain wrapped around the FOR statement. If you need more of the pseudocode, let me know. I'm trying not to make this post too big.


    TEXTBOOK PSEUDOCODE:

    Code:
    For K = Count + 1 Step 1 To Length(FullName)
    Set LastName[K] = FullName[K]
    MY POTENTIAL PROBLEM CODE:

    Code:
    for (k = (Count+1); k>strlen(FullName); Count+1)
    {LastName[k] = FullName[k];}
    __________________________________________________ __

    MY FULL CODE:

    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    
    using namespace std;
    
    
    
    int main ()
    {
    
         char FullName[30];
         char FirstName[15];
         char LastName[15];
    
         char FirstInitial, LastInitial;
         int k, Count;
    
         cout << "Enter a name with first name first:";
         cin.getline (FullName,30);
    
         Count = 1;
    
         while (FullName[Count] != ' ')
              {
                        FirstName[Count] = FullName[Count];
                       Count = Count + 1;
              }
    
         FirstInitial = FullName[0];
         LastInitial = FullName[Count+1];
    
         for (k = (Count+1); k>strlen(FullName); Count+1)
              {LastName[k] = FullName[k];}
    
         cout <<LastName << ", " <<FirstName;
    
    
         return 0;
    }
    Last edited by jtkhoskinson; 03-27-2010 at 12:26 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I hate pointers or Pointer Issues
    By bolivartech in forum C Programming
    Replies: 9
    Last Post: 11-14-2009, 11:48 AM
  2. My new ASUS Crosshair 2 Formula issues
    By VirtualAce in forum Tech Board
    Replies: 8
    Last Post: 03-02-2009, 08:47 PM
  3. Better spacing issues
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2008, 04:46 PM
  4. Multi-platform support issues.
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-27-2004, 06:41 PM
  5. hexdump issues
    By daluu in forum C Programming
    Replies: 2
    Last Post: 03-04-2003, 09:01 PM