Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

warpsycho666

Problem with Compiling

This topic is 5354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I need some help. I just got back into programming after 3 years now. All I had was the basics. Anyway I still have the C++ for Dummies book I used to get head start over every1 else back then. Anyway onto the problem. I hunted for a free compiler and I liked and downloaded Bloodshed Dev C++. It works good. I know there was similar post a few days ago but it didn''t help solve my problem. I even ran the code the other person was running with the suggested fixes. The problem is I run the program and it stats "Enter the tempature in Celsius:" When you enter a number then hit enter it dissapears. And this probelm is mentioned in the book for the compiler it supplies GNU. So the program works. But I still want to make it run so I can keep the program running and in the exe see the results. Any suggestions or fixes? Also if the code is needed ill post it. Also off topic but I registered with Game Dev, got my email. Finally managed to get it to work. Now im logged in but I still have to enter my name and password when i post, while im registered and logged in. Why is that? Thx for any help.

Share this post


Link to post
Share on other sites
Advertisement
If you mean your console window is disappearing once the program finishes executing, you need to add the line

system("PAUSE");

right before you return from your main function.

Dylan

Share this post


Link to post
Share on other sites
Well, I'll give you a code for a simple program I made for you to study...


#include <iostream>
#include <stdlib.h>

using namespace std; // You need this for

// 'system("PAUSE") to work.

int main()
{
int celsius;

cout << "Enter the tempature in Celsius: ";
cin >> celsius; // Takes what you entered.

cout << "\n\nYou entered: " << celsius << "\n\n"; // Shows what you entered.


system("PAUSE"); // Pauses the program until

// You hit a key.


return 0;
}




[edited by - WaterMelon34 on April 13, 2004 12:01:44 AM]

[edited by - WaterMelon34 on April 13, 2004 12:02:30 AM]

Share this post


Link to post
Share on other sites
First off thx for the help. Also thx for sample program. The system pause works with My name and the example. However now the code doesnt work and is producing errors. I know this is my first exercise and im looking into that free C++ tutorial that is on some posts. Because I dont know whats wrong. I don''t know if its the code for the dummies book or what. The code is identical to how its written in the book except the comments. I adjusted those to my liking. Anyway here is the code itself. One note however the first time I ran it I used Watermelon''s after it didnt work I ran it with the Dummies book thats the current shape the code is in. Anyway onto the code.


// Mike
// 4/14/04
// C++ Dummies Exercise
// Program converts Celsius tempature to Fahrenheit tempature
// Fahrenheit = Celsius * (212 - 32)/100 = 32
//


#include <iostream>
#include <stdio.h>

int main(int nNumberofArgs, char* pszArgs[])
{

// enter the tempature in Celsius
int celsius;
cout << "Enter the tempature in Celsius:";
cin >> celsius;

//calculate conversion factor for Celsius to Fahrenheit
int factor;
factor = 212 - 32;

//use conversion factor to Celsius into Fahrenheit
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results
cout << "Fahrenheit value is:";
cout << fahrenheit;

system("PAUSE");
return 0;

}

Thats the code now. Here is the compile log.

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Documents and Settings\Mike\Desktop\programming\Conversion.cpp" -o "C:\Documents and Settings\Mike\Desktop\programming\Conversion.exe" -pg -g3 -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:/Documents and Settings/Mike/Desktop/programming/Conversion.cpp: In function
`int main(int, char**)'':
C:/Documents and Settings/Mike/Desktop/programming/Conversion.cpp:17: `cout''
undeclared (first use this function)
C:/Documents and Settings/Mike/Desktop/programming/Conversion.cpp:17: (Each
undeclared identifier is reported only once for each function it appears
in.)
C:/Documents and Settings/Mike/Desktop/programming/Conversion.cpp:18: `cin''
undeclared (first use this function)

Execution terminated

Anyway thx again for the orginal help. And any new help.

Share this post


Link to post
Share on other sites
DO NOT USE system! I made a similar post earlier, system is very dangerous and platform dependant! Use cin.get() , under , std namespace. BTW you forgot to say using namespace std; after you included iostream.



#include <iostream>
#include <stdio.h>

using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{

// enter the tempature in Celsius

int celsius;
cout << "Enter the tempature in Celsius:";
cin >> celsius;

//calculate conversion factor for Celsius to Fahrenheit

int factor;
factor = 212 - 32;

//use conversion factor to Celsius into Fahrenheit

int fahrenheit;
fahrenheit = factor * celsius/100 + 32;

// output the results

cout << "Fahrenheit value is:";
cout << fahrenheit;

cin.get();
return 0;

}



should fix it.

[edited by - Drakkcon on April 14, 2004 5:39:16 PM]

[edited by - Drakkcon on April 14, 2004 5:39:39 PM]

Share this post


Link to post
Share on other sites
Well first off thx Drakkcon. Your code produced no errors. Also for pointing out me missing the using namespace std;. It''s hard working with the dummies book cause it seems so different from all the examples on this board and examples on webpages. Easy to check the book and forget some of the new bits of code I need. I ran your code and it worked. Produced to no error at all. But still the console window didnt stay up. So then after some aggravation I reran your code. But added the system pause. It worked. It allowed me to see the Fahrenheit value. Now im concerned with your warning of not to use System pause. Even though it may be conveint now on simple learning programs. I dont want to form any bad habits when I pursue the path of making projects on my own.

Anyway enough rambling but my questions are what makes system pause so bad? Dangerous and so forth. And if there is a true alternative. Or what about some of the bigger more complex exercises in the dummies book. Will it play a serious factor in those? Im gonna consult the www.cplusplus.com site tutorial more in depth to. Also see what I can learn on the compiler im using. But again thx for the help.

Share this post


Link to post
Share on other sites
Thnx man now i understand how that can be a problem in the future. Ill stay away from it. However now im still left with no results being displayed. I have to ethier be doing something wrong or there is simple way to resolve the console closing. Or was the void console command it?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!