473,405 Members | 2,154 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,405 software developers and data experts.

why does my Program keep getting me an error!

My program keeps getting me and error and i dont why

here is the error message

  • error C2061: syntax error: identifier 'infile'
  • error C2660: 'ReadDate' : function does not take 6 arguments
  • error C2086: 'char &junkChar' : redefinition
  • see declaration of 'junkChar'
My Program keeps giving me an error and i dont know why





here is the code
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <cmath>
  6.  
  7.  
  8.  
  9. using namespace std;
  10. void ReadDate(ifstream&, infile, int&,  char&, int&, char&, int&);
  11.  
  12. int main()
  13.  
  14. {
  15.     ifstream infile("F:\\data2.txt");
  16.     int numberOfLines;
  17.     int month;
  18.     int day;
  19.     int year;
  20.     char junkChar;
  21.  
  22.     infile >>numberOfLines;
  23.  
  24.     for(int k =1; k<=numberOfLines; k++)
  25.     {
  26.         ReadDate(infile, month, junkChar, day, junkChar, year);
  27.         cout << month << junkChar<< day << junkChar << year << endl;
  28.     }
  29.  
  30.  
  31.  
  32.     return 0;
  33. }
  34. void ReadDate(ifstream& infile, int&month, char& junkChar, int&day, char& junkChar, int&year)
  35. {
  36.     infile >> month >> junkChar >> day >> junkChar >> year;
  37. }
  38.  
  39.  
Nov 2 '08 #1
10 3022
JosAH
11,448 Expert 8TB
At line #10: get rid of the commas between the type and identifier names.

kind regards,

Jos
Nov 2 '08 #2
hi
i took out the commas but these two errors messages wont go away.


error C2086: 'char &junkChar' : redefinition

see declaration of 'junkChar'
Nov 2 '08 #3
JosAH
11,448 Expert 8TB
You're using 'char& junkChar' twice in your function's parameter list; the second
one is considered a re-definition.

kind regards,

Jos
Nov 2 '08 #4
what does this mean

Expression:string subscript out of range
Nov 2 '08 #5
JosAH
11,448 Expert 8TB
thanks that worked

i have one more question
what does this warning mean"

warning C4552: '+' : operator has no effect; expected operator with side-effect

this is the part of code where the warning came from.
Expand|Select|Wrap|Line Numbers
  1.  
  2. integerDigit=int(accountNumber[m])-int('0');
  3.             if(m%2==0)
  4.             {
  5.                 weightedSum +(2*integerDigit)/10 +(2*integerDigit)%10;
  6.             }
  7.             else
  8.             {
  9.                     weightedSum = weightedSum+integerDigit;
  10.  
  11.             }
  12.  
There is no assignment (side effect) in the expression in the if-clause.

kind regards,

Jos
Nov 2 '08 #6
whats missing in the if-clause
Nov 2 '08 #7
boxfish
469 Expert 256MB
If you want to add something to a variable, use the += operator.
Nov 2 '08 #8
JosAH
11,448 Expert 8TB
whats missing in the if-clause
A side effect (e.g. an assignment operator) in the expression in the if-clause.
The compiler was whining about it as I already told you in my previous reply.

kind regards,

Jos
Nov 2 '08 #9
Ok my program calculates all that i need to calculate and for it to work. im reading my data from an infile and writing it into a outfile.

the problem is that my program is reading my data only the first line all three times.
i want the program to read all three lines of the data and not just the first line 3 times.
how do i fix that


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <cmath>
  5. #include <iomanip>
  6.  
  7.  
  8. using namespace std;
  9. void ReadDate(ifstream& infile, int&,  char&, int&, int&);
  10. void ReadName(ifstream& infile, string&, string&);
  11. void ReadCreditCardNumber(ifstream& infile, string&);
  12. void ReadCheckDigit (ifstream& infile, int&);
  13. void ReadExpiration(ifstream& infile, int&);
  14. int main()
  15.  
  16. {
  17.     ifstream infile("F:\\data2.txt");
  18.     ofstream outfile("F:\\cardinfo.txt");
  19.     int numberOfLines;
  20.     int month;
  21.     int day;
  22.     int year;
  23.     char junkChar;
  24.     string firstName;
  25.     string lastName;
  26.     int weightedSum;
  27.     int integerDigit;
  28.     string accountNumber;
  29.     int checkDigit;
  30.     int expirationYr;
  31.     const string FIRST6_DIGITS = "601100";
  32.     const int FIRST6_DIGIT_SUM = 6;    
  33.  
  34.     outfile << " Name " << "                "<< "Card Number" << "               "<< "Expiration Date" << endl;
  35.  
  36.     infile>> numberOfLines;
  37.  
  38.     for(int k =1; k<=numberOfLines; k++)
  39.     {
  40.         ReadDate(infile, month, junkChar, day, year);
  41.         outfile << month << junkChar<< day << junkChar << year << ' ';
  42.         ReadName(infile, firstName, lastName);
  43.         outfile <<left <<firstName<< ' '<< lastName <<' ';
  44.         ReadCreditCardNumber(infile, accountNumber);
  45.  
  46.  
  47.         weightedSum=FIRST6_DIGIT_SUM;
  48.         for(int m = 0; m < 9; m++)
  49.         {
  50.             integerDigit= int(accountNumber[m])-int('0');
  51.             if(m%2 ==0)
  52.             {
  53.                 weightedSum = (2*integerDigit)/10 +(2*integerDigit)%10;
  54.             }
  55.             else
  56.             {
  57.                 weightedSum = weightedSum+integerDigit;
  58.  
  59.             } 
  60.         }
  61.         checkDigit = 10-weightedSum%10;
  62.         if(checkDigit == 10)
  63.         {
  64.             checkDigit =0;
  65.         }
  66.         outfile << right<< FIRST6_DIGITS.substr(0,4) << ' ';
  67.         outfile << FIRST6_DIGITS.substr(4,2) << accountNumber.substr(0,2) << ' ';
  68.         outfile << accountNumber.substr(2,4) << ' ' << accountNumber.substr(6,3) << checkDigit;
  69.  
  70.         ReadExpiration(infile, expirationYr);
  71.  
  72.         expirationYr=(year + 2)%100;
  73.         outfile << right << month/10 << month%10 << '/';
  74.         outfile << expirationYr/10 << expirationYr%10 << endl;
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.     }
  83.     infile.close();
  84.     outfile.close();
  85.  
  86.  
  87.  
  88.     return 0;
  89. }
  90. void ReadDate(ifstream& infile, int& month, char& junkChar, int& day,  int& year)
  91.  
  92. {
  93.     infile >> month >> junkChar >> day >> junkChar >> year;
  94. }
  95. void ReadName(ifstream& infile, string& firstName, string& lastName)
  96.  
  97. {
  98.     infile >> firstName >> lastName;
  99. }
  100. void ReadCreditCardNumber(ifstream& infile, string& accountNumber)
  101.  
  102. {
  103.     infile >> accountNumber;
  104. }
  105. void ReadCheckDigit (ifstream& infile, int& checkDigit)
  106.  
  107. {
  108.     infile >> checkDigit;
  109. }
  110. void ReadExpiration(ifstream& infile, int& expirationYr)
  111. {
  112.     infile >> expirationYr;
  113. }
  114.  
Nov 2 '08 #10
boxfish
469 Expert 256MB
What may be happening is that infile has failed. This happens when the file contains data that cannot be stored in the variable you are reading into. Once it has failed, it will not read any more, and the variables you are reading into will contain the values from the last time you used them. I don't know that this is what is happening, but it would cause the same values to be written to outfile over and over. The function infile.fail() will return true if infile has failed. Try writing out the result of a this function to outfile a few times in your program so you can see when or if the file fails. Again, I don't know for sure that this is what's happening, but I hope this helps solve the problem.
Nov 2 '08 #11

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

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
12
by: Fred Pacquier | last post by:
First off, sorry for this message-in-a-bottle-like post... I haven't been able to phrase my questions well enough to get a meaningful answer from Google in my research. OTOH, it is standard...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.