All Right.

Posts 1–15 of 16 · Page 1 of 2
All Right.
I'm home now.

Here's the code that I was trying to compile that required the #include stdafxs.h

Code:
/*My second cpp programs
 with comments in it :)*/

#include stdafx.h

#include <iostream>
using namespace std;

int main()
{ 
	cout << "Hello World!"; //prints Hello World!
	cout << "I am a c++ Program!"; //prints I am a c++ Program
	cin.get();
	return 0;
}
If you just want to output "hello world" onto your screen you dont need the
cin.get();

My "hello world" source was just:

Code:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
cout << "i am a C++ program" << endl; //added for your benefit.

system ("pause");
return 0;
}
Quote Originally Posted by Generist View Post
If you just want to output "hello world" onto your screen you dont need the
cin.get();
I wanted to read the text it typed out because without the pausing, it went to fast for me to even see

system ("pause") would work in place of cin.get() right?
yes it would. Or even,
Sleep(1000); //time is in milliseconds
would work.

To use sleep you need the header
#include <windows.h>
Quote Originally Posted by Generist View Post
yes it would. Or even,
Sleep(1000); //time is in milliseconds
would work.

To use sleep you need the header
#include <windows.h>
Alright Much appreciated.

So I would always have to include the snippet #include "stdafx.h" at the beginning of every cpp file right??
You shouldnt need
#include "stdafx.h"
if you use

Code:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
cout << "i am a C++ program" << endl; //added for your benefit.

system ("pause");
return 0;
}
Quote Originally Posted by Generist View Post
You shouldnt need
#include "stdafx.h"
if you use

Code:
#include <iostream>
using namespace std;
int main()
{
cout << "hello world";
cout << "i am a C++ program" << endl; //added for your benefit.

system ("pause");
return 0;
}
Before I compiled what I had, I didn't include #include "stdafx.h" at the beginning of the code.

When it wasn't there, an error came up.

the error was:

Code:
c:\documents and settings\kelvin yeh\my documents\visual studio 2008\projects\hello world; comments\hello world; comments\hello world; comments.cpp(16) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Take it out of precompiled headers or just use a blank source. Better yet, use DevC++.
Quote Originally Posted by Generist View Post
Take it out of precompiled headers or just use a blank source. Better yet, use DevC++.
Help help help!!

Code:
//This is practice for stringing and using variables. attempt #1 to make a basic add,sub.,multi.,divide calculator :)

#include "stdafx.h"

#include <iostream>
#include <string>

using namespace std;
{
	int a;
	int b;
	int result = a + b;
	cout << result << endl;
	int result = a - b;
	if b > a then int result = b - a;
	cout << result << endl;
	int result = a * b;
	cout << result << endl;
	float int result = a / b;
	cout << result << endl;

	system ("pause");
		return 0;
}
That was my attempt at using what I learned so far to make a basic calc.

I just wanted to see what I was capable of.

I compiled it and it came up with errors...

Can you help spot what I'm doing wrong?
Quote Originally Posted by KABLE View Post
Help help help!!

Code:
//This is practice for stringing and using variables. attempt #1 to make a basic add,sub.,multi.,divide calculator :)

#include "stdafx.h"

#include <iostream>
#include <string>

using namespace std;
{
	int a;
	int b;
	int result = a + b;
	cout << result << endl;
	int result = a - b;
	if b > a then int result = b - a;
	cout << result << endl;
	int result = a * b;
	cout << result << endl;
	float int result = a / b;
	cout << result << endl;

	system ("pause");
		return 0;
}
That was my attempt at using what I learned so far to make a basic calc.

I just wanted to see what I was capable of.

I compiled it and it came up with errors...

Can you help spot what I'm doing wrong?
just continue with your tutorial first.
it will all be explained...
you get errors because a & b have no value.
and when a variable is declared such as "int result" the next time you us it you dont have to say int before it.
the type cant be changed while using the program.
PM'ing you a response now.
I got the errors fixed with Generist's help. when I get home in like 7 minutes, I'll put up the altered version
I have to say, all of your methods of pausing are disgusting.

Here's some proper code.
Code:
//intern
#include "stdafx.h"
//extern
#include <iostream>
#include <conio>

static void pause()
{
      cout << "Press any key to continue..." << endl;

      _getch();
}

int main()
{
       cout << "Aye yo, world, fuck you." << endl;

       //pause
       pause();
}
Quote Originally Posted by litebrand View Post
I have to say, all of your methods of pausing are disgusting.

Here's some proper code.
Code:
//intern
#include "stdafx.h"
//extern
#include <iostream>
#include <conio>

static void pause()
{
      cout << "Press any key to continue..." << endl;

      _getch();
}

int main()
{
       cout << "Aye yo, world, fuck you." << endl;

       //pause
       pause();
}
I'm LEARNING how to code
Quote Originally Posted by KABLE View Post
I'm LEARNING how to code
Bahh, sorry, refer to that when you get past the function section of w/e you are studying.

Particularly the keywords in initiation of pause.
Posts 1–15 of 16 · Page 1 of 2
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us