473,388 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 alahliunitedbank 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@company_name.com.country_code

After the execution, the outdata.txt should contain:

email removed

************************************************** *******************
My soultion is:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>  
  2. #include<fstream>                      
  3. using namespace std;                       
  4.  
  5. int main() 
  6. {         
  7.  
  8.  
  9.  
  10.     string Fname,lname;
  11.     string company_name,country_code;
  12.     char '@';
  13.  
  14.     ifstream infile;
  15.     ofstream outfile;
  16.  
  17.     infile.open("inData.txt");
  18.     outfile.open("outData.txt");
  19.  
  20.     infile>>Fname>>lname ;
  21.     infile>>company_name>>country_code>>endl;
  22.  
  23.     outfile<<"Fname_lname"<<'@'<<"company_name"<<.com<<".country_code"<<endl;
  24.  
  25.     infile.close();
  26.     outfile.close();
  27.  
  28.     return 0;                           
  29. }
  30.  
My question is what the wrong in my solution?

{Thanks slots}
Jul 17 '07 #1
5 1480
[i]Hello...


After the execution, the outdata.txt should contain:

Sarah_AlSammak@alahliunitedbank.com.bh

What IS the output now?

J
Jul 17 '07 #2
scruggsy
147 100+
Your output statement is all messed up:
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. 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.
Jul 18 '07 #3
sicarie
4,677 Expert Mod 4TB
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...
Jul 18 '07 #4
thanks for every body who write a reply
Jul 18 '07 #5
sicarie
4,677 Expert Mod 4TB
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.
Jul 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: nyy | last post by:
This is a program that is supposed to save the user name and password in cookies, and when the user comes back to login and he enters the same user name and password, a pop up message welcome him...
5
by: CoreyWhite | last post by:
It is possible to use martingale probability theory to beat some games of chance. In a fair game of coin toss, where the odds reach an equilibrium of 50/50 chain reactions do occur. This can be...
19
by: mohammaditraders | last post by:
a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the...
5
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions...
4
by: isabelle | last post by:
hi, every body.. help me in this program. please!! write a c++ program that converts hexadecimal digit to its corresponding decimal value. input/output: Enter a hexadecimal digit :A The...
10
by: len | last post by:
I have created the following program to read a text file which happens to be a cobol filed definition. The program then outputs to a file what is essentially a file which is a list definition...
1
by: veer | last post by:
hi i think it's a silly question but i am very confused about this actually i made program on spell check.This is done by creating object of msword and then with the help of this object i create...
0
by: progvar | last post by:
hi i am getting probleum in converting a spell check progrma made in vb 6.0 and Ms-office Word into OpenOffice Word when i made spell check program in Ms-Word and vb 6.0 it works fine but i use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.