CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2010
    Posts
    46

    Help understanding

    hey guys this is a homework question, so to be straight foward I am NOT looking for ya'll to solve the problem for me. that being said I am writing my second c++ program. I have built a solution and I have 2 errors and 2 warnings. here are the parameters of the assignment

    Write a program using the fstream function that will take information from a text file, manipulate the information and output it into a second text file.

    here is the source code

    //Kraig Holdren
    //CS106
    //Ken Washington
    // March 25, 2010

    //This program will take information from the text file "inData.txt"
    //manipulate the data and output the results into a seperate text file.

    #include <iostream>
    #include <fstream>

    using namespace std;

    int main ()
    {
    //stream variables
    ifstream inFile;
    ofstream outFile;
    //variables to be calculated
    int Sum;
    int Product;
    char A;

    //Tells the program what file to open
    inFile.open("inData.txt") ;
    //program will create this file for the output
    outFile.open("outData.txt") ;

    inFile >> A;
    outFile << "The character from the file is K" << endl;

    inFile >> 10, 10;
    Sum = 10 + 10; endl;
    outFile << "The Sum of 10 + 10 =" << Sum << endl;

    inFile >> 10, 10;
    Product = 10 * 10; endl;
    outFile << "The Product of 10 * 10 =" << Product << endl;

    inFile.close();
    outFile.close();

    return 0;

    }

    the errors I am getting are

    LINE 32 AND 36: error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)

    and 2 warnings

    LINE 33, 37: warning C4551: function call missing argument list

    Like I said in the begining I dont want you guys to do the assignment for me, I am just thick headed and need help understanding why I have come to these problems

    Thanks

    Kraig

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Help understanding

    Code:
    inFile >> 10, 10;
    What are you trying to do here?

  3. #3
    Join Date
    Mar 2010
    Posts
    46

    Re: Help understanding

    the paramiters of the assignment say to create a text file. on the first line put a letter. on the second line 2 two digit numbers.

    the program needs to take that letter and out put

    "the character from the file is ___"

    "the sum of the two numbers is ____ + ____ = _____"

    "the product of the two numbers _____ + _______ = _____

    the numbers i choose were 10 and 10. the letter i choose was A.

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Help understanding

    Well, that letter and those numbers should be in the input file, not in the source code! The source code should work with an input file containing any letter and pair of numbers.

    The error is telling you that an integer literal is not a valid place to store a value read from the file. You need to be reading into an int variable.

    Calling the char A actually does work, since A is a valid variable name, but the character stored in A might not be 'A'----it could be anything in the file.

    Also, the comma operator does not do what you think it does.
    Last edited by Lindley; March 26th, 2010 at 11:26 AM.

  5. #5
    Join Date
    Mar 2010
    Posts
    46

    Re: Help understanding

    Thanks fou your help Lindley. I ended up having an email marathon with my professor as he helped me figure out the errors. here is the source code if your interested.

    //This program will take information from the text file "inData.txt"
    //manipulate the data and output the results into a seperate text file.

    #include <iostream>
    #include <fstream>

    using namespace std;

    int main ()
    {
    //stream variables
    ifstream inFile;
    ofstream outFile;
    //variables to be calculated
    int Sum;
    int Product;
    int Number1;
    int Number2;
    char A;

    //Tells the program what file to open
    inFile.open("inData.txt") ;
    //program will create this file for the output
    outFile.open("outData.txt") ;

    inFile >> A;
    outFile << "The character from the file is A" << endl;

    inFile >> Number1 >> Number2 ;
    Sum = Number1 + Number2 ;
    outFile << "The Sum of 10 + 10 = " << Sum << endl;

    inFile >> Number1 >> Number2 ;
    Product = Number1 * Number2 ;
    outFile << "The Product of 10 * 10 = " << Product << endl;

    inFile.close();
    outFile.close();

    return 0;

    }

  6. #6
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Help understanding

    If you think that's your finished code, what about these two lines:
    outFile << "The Sum of 10 + 10 = " << Sum << endl;

    outFile << "The Product of 10 * 10 = " << Product << endl;
    I believe the Sum of 10 + 10 is 20, no matter what your program says, likewise, the Product of 10 * 10 is 100.

    Look at your code closely.

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Help understanding

    Yes, you should be outputting the variables there rather than hard-coding 10.

  8. #8
    Join Date
    Mar 2010
    Posts
    2

    Unhappy Re: Help understanding

    I can not understand C ++ in any way.

  9. #9
    Join Date
    Jun 2005
    Posts
    315

    Re: Help understanding


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured