|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ghosty1212 (5) | |||
So I just picked up a book on C++ probably an hour ago, and I seem to be having problems already. So this is my code, I was wondering if anybody could tell me what I can do to fix the error in the line of code where it says (float)? Thanks in advance.
| |||
|
Last edited on
|
|||
| Bazzy (6258) | |
You need to have 5 or 8 to be float, the way you are doing it is like this: float( int(5) / int(8) ) so 5/8 returns an integer and the result should be 0 if you change it in float( 5 ) / 8 the result will have float as type as this is the bigger type in the expression.To make it shorter you could type 5.0f / 8 'f' means 'float' if you write only 5.0 it will have as type doublePS: If you want to see a very big number try -1ull | |
|
Last edited on
|
|
| ghosty1212 (5) | |
All right, thanks. Now it presents this weird error code that I can't seem to fix... I understand what it's asking me to fix, but I try to edit it and nothing happens... Here's the error code: 15 C:\Documents and Settings\Owner\My Documents\C++ Projects\usingcout.cpp expected `;' before "std"
| |
|
|
|
| Bazzy (6258) | |
You forgot a ';' after std::cout << "Here's a fraction:\t\t"(When posting code use the [code][/code] tags) | |
|
Last edited on
|
|
| ghosty1212 (5) | |
| Thank you, thank you so very much! I did exactly what you said and it all works now... Thank you! | |
|
|
|
| ghosty1212 (5) | |
| Well now there is another problem... lol.... When I compile the code and then run it the Command Box screen just flashes.... And that's all. Is anything wrong with my compiler type? Or something like that? | |
|
|
|
| modulo51 (7) | |
|
When the program ends the box dissappears. This is such a common situation for beginners to learn about that it's addressed in the beginners forum under: 'console closing down'. | |
|
Last edited on
|
|
| Bazzy (6258) | |
| And the solution is here: http://www.cplusplus.com/forum/beginner/1988/ | |
|
|
|
| ghosty1212 (5) | |
| Thank you both, I used the system ("PAUSE") command and it worked out well... Thank you very much! But I used to be able to do it without it, and now it does that... But oh well, I'm going to use this code from now on. Thank you again! | |
|
|
|
| firedraco (4744) | |
| DON'T use system("pause")....it FAILS. I would suggest using the second post in that topic... | |
|
|
|
| grey127 (32) | |
|
// Listing 2.2 using std::cout #include <iostream> int main() { std::cout << "Hello there.\n"; std::cout << "Here is 5: " << 5 << "\n"; std::cout << "The manipulator"; std::cout << "writes a new line to the screen."; std::cout << std::endl; std::cout << "Here is a very big number:\t" << 7000; std::cout << std::endl; std::cout << "Here is the sum of 8 and 5:\t"; std::cout << (8+5) << std::endl; std::cout << "Here's a fraction:\t\t"; std::cout << float (5/8) << std::endl; std::cout << "Ghosty1212 is a C++ Programmer!\n"; return 0; } | |
|
|
|