Sign in to follow this  
C_Programmer0101

Dev C++ Help

Recommended Posts

Quote:
Original post by C_Programmer0101
When I put in code in C++ it goes to the press any key mode. How can I make it so I can see hello world or even interact with other users.

here
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
cout <<"hello world";
system("pause");
return 0;
}

Share this post


Link to post
Share on other sites
Ok maybee I am still not clear. After I compiled and ran my program it does not show the hello world at all. It just shows press any key to continue.

#include <iostream>

int main()
{
cout <<"hello world";
system("pause");
return 0;
}

What do I need to do to see the hello world portion?

Share this post


Link to post
Share on other sites
No I have not used namespace std; and yes I do get compiler errors and this is what is confusing me as a newbee. In Python if there is any errors it will not compile but in Dev C++ it will. What would a correct code look using a simple If statement for How old are you so I can see what all I have been missguided on. I have been using online tutorials.

Share this post


Link to post
Share on other sites
Ah, I think I see the problem.

You will have to look at the errors that are returned by the compiler and fix them. In your case, you will have to declare using namespace std; before your main routine, or use std::cout << "hello world!"; instead.

If you're unsure, post your errors up here as it'll help with a diagnosis of the problem.

Share this post


Link to post
Share on other sites
I have just compiled the code with the using namespace std;. Its screwed, and so to fix this add << endl; to cout << "hello world"

the code should look like this:
#include <iostream>
using namespace std;
int main()
{
cout <<"hello world";
system("pause");
return 0;
}



don't you have a book you can look at??

Share this post


Link to post
Share on other sites
Im at work right now and I will try it as soon as I get off but the program should look like this you say:

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
std::cout <<"hello world"; /*STD would be in this line*/
system("pause");
return 0;
}

Share this post


Link to post
Share on other sites
Compiles fine in my Dev-Cpp, no errors and I get "hello worldPress any key to continue..."(there´s no '\n' or endl there ;)).
You don´t need to add "using namespace std" according to current C++ specs. cout is enough.
Do you have the 4.9.9.0 version of Dev-Cpp?

ch.

Share this post


Link to post
Share on other sites
This code shows only this on my screen: Press any key to continue............

#include <stdlib.h>
#include <iostream>
using namespace std;

int main()

int min=0, max=0, i=0;

cout << "Input your first number to count from: ";

cout << "Input your last number to count to: ";
"
cin >> max;


for(i=min; i <= max; i++)
{
cout << i << endl;
}
system("pause");
return 0;
}

Very weird considering the program skips conditions on the for loop. Now my question is how do I stop it from doing that.

Share this post


Link to post
Share on other sites
First off, you have no opening bracket for your main() function. There are numerous other errors there too. Technically, that shouldn't even compile.

This works fine for me:

/* [GameDevExamples\TestCounter\TestCounter.cpp]
*
* Autogenerated with k2_Doc2Code tool.
*
* Description:
* Simple counting program.
*/


#include <iostream>

int main()
{
int minValue = 0;
int maxValue = 0;

std::cout << "Enter minimum value and maximum value: " << std::endl;
std::cin >> minValue >> maxValue;
std::cout << "Counting from [" << minValue << "] to [" << maxValue << "]:" << std::endl;

for (int i = minValue; i <= maxValue; i++)
{
std::cout << "Current value: " << i << std::endl;
}

return 0;
}




Sample output:
Quote:
Enter minimum value and maximum value:
4 13
Counting from [4] to [13]:
Current value: 4
Current value: 5
Current value: 6
Current value: 7
Current value: 8
Current value: 9
Current value: 10
Current value: 11
Current value: 12
Current value: 13
Press any key to continue

Share this post


Link to post
Share on other sites
Quote:
Original post by C_Programmer0101
This code shows only this on my screen: Press any key to continue............

#include <stdlib.h>
#include <iostream>
using namespace std;

int main()

int min=0, max=0, i=0;

cout << "Input your first number to count from: ";

cout << "Input your last number to count to: ";
"
cin >> max;


for(i=min; i <= max; i++)
{
cout << i << endl;
}
system("pause");
return 0;
}

Very weird considering the program skips conditions on the for loop. Now my question is how do I stop it from doing that.

Is this an exact copy of your code? Because if it is then it shouldn't even compile. Right off hand, you need an opening brace after the int main() and there's a quotation mark sitting all alone on the line before cin >> max;.

Also, while this won't cause an error, you have two couts in a row asking for information, but only one cin to get input. I would rewrite it like so:


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

using namespace std;

int main(int argc, char** argc) {

int min, max;

cout << "Input your first number to count from: ";
cin >> min;

cout << "Input your last number to count to: ";
cin >> max;

//Note: You don't actually need an i variable, you could just use min, since you won't be needing its value again
for(int i = min; i <= max; i++) {

cout << i << endl;

}

system("pause");
return 0;

}

Share this post


Link to post
Share on other sites
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
int min,max;

cout <<"enter minimum";
cin >>min;

cout <<"\nenter maximum";
cin >>max;

for(int i = min;i <= max; i++)
{
cout <<i;
}
system("pause");
return 0;
}



it works I tested it.

[Edited by - hothead on November 11, 2004 9:55:40 PM]

Share this post


Link to post
Share on other sites
all right C_Programmer0101, you need to start from scratch because this isn't getting anywhere. Mage's code is correct, the source formatting makes it look like it isn't.
if hothead's code doesn't work, read on. otherwise don't.

open dev c++ 4.9.9.0.
(on the menu)New->Project
click the "Console Application" icon, and name it "test". save it somewhere.

it will open with a project workspace, and an unsaved file. push Ctrl + S (or whatever save method you prefer) and save it as main.cpp (not .c or .h).

the template will have created a basic code framework. push Ctrl + F9 to build and compile your application. push F9 to run it. it should produce the following : "press any key to continue".

now before the "system("PAUSE"); add the following lines :

int a;
cout << "Hello World";
cin >> a;
cout << endl << "You chose " << a << endl;

repeat the build procedure (you have to rebuild after every modification) it should allow you to input a number, and spit it out.

Share this post


Link to post
Share on other sites
I used hotheads code and it flickered on the screen and then I followed your steps. The first attempt did exactly what you said and then I input the following:

int a;
cout << "Hello World";
cin >> a;
cout << endl << "Hello World" << a << endl;

I could not see the hello world I only seen press any key to continue

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this