Check this program for me. please!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isabelle
    New Member
    • Dec 2006
    • 14

    Check this program for me. please!!

    Hello...

    How are you every body?

    I want from you to check this program..

    *************** *************** *************** *****
    Suppose that the file inData.txt contains the following data:
    Sarah AlSammak alahliunitedban k bh

    Write a C++ program that read from the inData file the first string as a first name, the second string as a last name, the third string as a company name and the last string as a country code. The aim of the program is to create an email for the user and store it in outData.txt file.

    The email structure is:
    Fname_lname@com pany_name.com.c ountry_code

    After the execution, the outdata.txt should contain:

    email removed

    *************** *************** *************** *************** *********
    My soultion is:
    [code=cpp]
    #include <iostream>
    #include<fstrea m>
    using namespace std;

    int main()
    {



    string Fname,lname;
    string company_name,co untry_code;
    char '@';

    ifstream infile;
    ofstream outfile;

    infile.open("in Data.txt");
    outfile.open("o utData.txt");

    infile>>Fname>> lname ;
    infile>>company _name>>country_ code>>endl;

    outfile<<"Fname _lname"<<'@'<<" company_name"<< .com<<".country _code"<<endl;

    infile.close();
    outfile.close() ;

    return 0;
    }
    [/code]
    My question is what the wrong in my solution?

    {Thanks slots}
    Last edited by sicarie; Jul 18 '07, 01:22 PM. Reason: Code tags
  • Hypnotik
    New Member
    • Jun 2007
    • 87

    #2
    Originally posted by isabelle
    [I]Hello...


    After the execution, the outdata.txt should contain:

    Sarah_AlSammak@ alahliunitedban k.com.bh

    What IS the output now?

    J

    Comment

    • scruggsy
      New Member
      • Mar 2007
      • 147

      #3
      Your output statement is all messed up:
      Code:
      outfile<<"Fname_lname"<<'@'<<"company_name"<<.com<<".country_code"<<endl;
      Enclosing something in double-quotes makes it a string literal. That means that it will be output exactly as you typed it. This is not what you want for things like Fname, lname, and company_name.
      Similarly, if you enclose a character in single quotes, it will be output exactly as typed. That is what you want for the '@' character.
      Anything not enclosed in quotes is an identifier (such as a variable). If the variable exists and is printable, its value will be printed. So if Fname holds the value "Tom", then this line will print out that name:
      Code:
      cout << Fname;
      Notice the lack of quotes?
      In your code, the only .com is outside of quotes, so the compiler sees that as an identifier and rejects it because [a] variable names can't start with a period and [b] even if they could, you never defined that variable.

      Hope this helps you see the solution.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        My question is: why are you unable to put this in a compiler and then Google whatever error messages that come out, or do like the Posting Guidelines say and ask a specific, pointed question (such as "Why is my output different from what I want, it's giving me ************ and I want ************")?

        Anyway, please read this thoroughly, Mods tend to not react well when you do things like ask someone else to compile your code, not use code tags, not use good thread titles, etc...

        Comment

        • isabelle
          New Member
          • Dec 2006
          • 14

          #5
          thanks for every body who write a reply

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by isabelle
            thanks for every body who write a reply
            You're welcome, but please be sure to follow the Posting Guidelines in the future, or you will not be allowed to post.

            Comment

            Working...