Thread: c++ programming help please

  1. #16
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    Its helping. I'm down to five now
    Code:
    1>.\assaignment1.cpp(32) : error C3861: 'setprecision': identifier not found
    1>.\assaignment1.cpp(45) : error C2296: '^' : illegal, left operand has type 'double'
    1>.\assaignment1.cpp(45) : error C2297: '^' : illegal, right operand has type 'double'
    1>.\assaignment1.cpp(46) : error C3861: 'setprecision': identifier not found
    1>.\assaignment1.cpp(53) : error C3861: 'setprecision': identifier not found
    I've been sitting in front of the computer for 5h now, whats setprecision, illegal, left operand has type 'double' and illegal, right operand has type 'double'? i'm starting to loose hope that i will ever get this done.

    edit: i've figured out setprecision
    Last edited by shock; 03-29-2008 at 02:25 AM.

  2. #17
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    float main() - something really new
    read the FAQ how to declare main

    show the code that does not works...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by shock View Post
    Its helping. I'm down to five now
    Code:
    1>.\assaignment1.cpp(32) : error C3861: 'setprecision': identifier not found
    1>.\assaignment1.cpp(45) : error C2296: '^' : illegal, left operand has type 'double'
    1>.\assaignment1.cpp(45) : error C2297: '^' : illegal, right operand has type 'double'
    1>.\assaignment1.cpp(46) : error C3861: 'setprecision': identifier not found
    1>.\assaignment1.cpp(53) : error C3861: 'setprecision': identifier not found
    I've been sitting in front of the computer for 5h now, whats setprecision, illegal, left operand has type 'double' and illegal, right operand has type 'double'? i'm starting to loose hope that i will ever get this done.

    edit: i've figured out setprecision
    You should look up ^, then. As mentioned, it is not raising to a power. I suppose you could look up raising to a power, while you're at it.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Due_Monday View Post
    Heres my sample output file:

    Code:
    {
    
    	ofstream outputFile;
    	outputFile.open("007.txt");
    
    	
    
    	outputFile << "haha\n";
    	outputFile << "z0mg\n";
    	outputFile << "wtf\n";
    	outputFile << "gay assignment\n";
    
    	outputFile.close();
    	
    
    	return 0;
    
    }
    That's no output file, that's your source code.

    The problem I'm encountering is how to get the input detail from my "cin" to show up on my Output files.
    You have to write it out. (That is, everything you write to the screen has to write to the file, and everything you read in you write that out too.)

    Is this the case with the Output file also? Because the output file is only working properly when it comes after:

    Code:
     
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    
    float main()
    
    {
    
    
    
    {
    
    	ofstream outputFile;
    	outputFile.open("wtf.txt");
    
    	
    
    	outputFile << "haha\n";
    	outputFile << "z0mg\n";
    	outputFile << "wtf\n";
    	outputFile << "gay assignment\n";
    
    	outputFile.close();
    	
    
    	return 0;
    
    }
    However if I put the code in that order, the rest of the coding is ignored. Any tips would be appreciated, cheers
    That makes no sense, but my Hat of Guessing wants to remind you that return means STOP and everything after that doesn't happen.

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    How do you write anything out?
    Code:
    cin >> stuff;
    outfile << stuff;

  6. #21
    Banned
    Join Date
    Nov 2007
    Posts
    678
    lol
    Code:
    cin >> number;
    outputFile << number;
    did you understand it? lol haha

    Edit: ditto reply! ditto timing! lol haha lol
    Last edited by manav; 03-29-2008 at 03:20 AM. Reason: loh haha

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by manav View Post
    lol
    Code:
    cin >> number;
    outputFile << number;
    did you understand it? lol haha

    ditto reply! ditto timing! lol haha lol
    I think lol guy got banned; you can stop now.

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Due_Monday View Post
    I meant how to include the "outfile << stuff;" with the text before it, ie. The length of the pendulum =
    That is the answer.
    Code:
    cout << "The length of the pendulum = ";
    outFile << "The length of the pendulum = ";
    cout << length << std::endl;
    outFile << length << std::endl;
    Everything you write to the screen you write to the output file.

  9. #24
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    whereabouts may I find the the FAQ
    Look in the header of the page for the word FAQ
    You may want to read several entries from it
    I was talking about this entry http://faq.cprogramming.com/cgi-bin/...&id=1043284376
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #25
    Registered User
    Join Date
    Mar 2008
    Posts
    4
    thanks for that, no more errors. yay. accept when the menu opens and i choose selection it doesnt take me to the calculations

  11. #26
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Due_Monday View Post
    Cheers!

    That was the problem I was having, because I did my coding one bit at a time it was all together, whereas I needed to integrate each piece individually. Thanks again.
    It doesn't matter how many pieces it's in, you just need to do both. (You could do it both couts in one statement, and the outFiles in one statement, but one statement for each.)

  12. #27
    Registered User
    Join Date
    Mar 2008
    Posts
    1
    Hi, another question sorry to bother you guys.

    How can I change the outputFile.txt to another directory? Is it possible to change the outputFile location to D:\?
    Last edited by Due_Monday; 03-29-2008 at 04:36 AM.

  13. #28
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Due_Monday View Post
    Hi, another question sorry to bother you guys.

    How can I change the outputFile.txt to another directory? Is it possible to change the outputFile location to D:\?
    Of course. Remember to escape backslashes a la \\.

  14. #29
    Registered User guesst's Avatar
    Join Date
    Feb 2008
    Location
    Lehi, UT
    Posts
    179
    Oh, and the carrot (^) isn't used in C/C++ for powers. You need to use the function in math.h pow().
    Type-ins are back! Visit Cymon's Games at http://www.cymonsgames.com for a new game every week!

  15. #30
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    the carrot (^)
    Caret. Carrots, unlike carets, are edible
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed