Thread: Novice needing help!

  1. #1
    Registered User
    Join Date
    Oct 2008

    Novice needing help!

    I have written this program as a homework assignment and can't get it quite right, hopefully someone can help me. The program should perform the following task:

    Design and document a program which uses a one-dimensional character array, and reads the string from an input data file and writes output to an output file.
    The userís data file should contain the userís name with first character capitalized: First name, Middle Initial, Last Name, and address, with zip code, separated by spaces or enters (endline or carriage returns).
    The program should read, from the user data file, the user's full name (first name, middle initial, last name) and address, display the full name, then find and display, from that string data, the user's nominal email name (nominally, in lower case, the first name, a dash, and the last name Then the program should display the userís address, calculate and display the number of characters in the user's total name and address. Finally, it should find and display the user's three initials in lower case. The output file should contain the same information in the same format as the display screen.

    I can get the program to work about 90% correctly, it does everything except write to an output file and I can't figure out how to convert my initials from uppercase to lowercase. In case anyone was wondering I am running this from Bloodshed Dev C++.

    What I have so far:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main()
    //Open program reading from text file
        ifstream fin("data.txt");
        string s;
        string info[5];
        string details[5];
        details[0] = "First name";
        details[1] = "Middle initial";
        details[2] = "Last name";
        details[3] = "Address";
        details[4] = "Email";
        int i = 0;
        while( getline(fin,s) ) 
         info[i] = s; 
         cout << details[i]<<" : " << s << endl;
    //Get total name,address, and initials
        int totalName = info[0].length()+info[1].length()+info[2].length();
        int totalAddress = info[3].length();
        string initials;
        for(int t= 0; t<3; t++)
        initials += (info[t]).substr(0,1);
    //Displays total name, address, and initials
        cout<<"number of characters in the user's total name : "<<totalName<<endl;
        cout<<"number of characters in the user's address : "<<totalAddress<<endl;
        cout<<"Initials : "<<initials;
    // End program
          cin.ignore(256, '\n');
          cout << "Press ENTER to continue..." << endl;
        return 0;
    Thanks for the help.

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Hmmmm well there are a couple ways of doing this but if you are just needing to make initials into caps...

    #include <cctype>
    void uppercasify(string &s)
      for(size_t i = 0, size = s.length(); i < size; ++i)
       s[i] = std::toupper(s[i]);

  3. #3
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Katy, Texas
    Quote Originally Posted by mc82
    ...Design and document a program which uses a one-dimensional character array, ..
    Newsflash... you've already missed the first directive of the assignment.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    Well God bless good ol' Eagle Eye for even reading the first paragraph of your post. I always read like two words... then see code then sort of skip to the beginning of the sentense that ends in a question mark.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 06-17-2005, 10:00 PM
  2. Rtfm
    By XSquared in forum A Brief History of
    Replies: 4
    Last Post: 03-13-2003, 05:19 PM
  3. help for a C novice
    By Unregistered in forum C Programming
    Replies: 8
    Last Post: 05-02-2002, 09:49 PM
  4. Novice needing help PLEASE!!!!!
    By Nick Dillon in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2002, 02:21 PM