| View previous topic :: View next topic |
| Author |
Message |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2220
|
Posted: Sun Mar 23, 2008 9:23 pm Post subject: What's wrong with this script? (C++) |
|
|
| Code: | #include <iostream.h>
int main(void)
{
cout << "Hello User!" " My name is JCoA\n" "There are many things that I can help you with\n" "I can do things such as: \n" "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
system("pause");
delay(2000);
return 0;
} |
It worked until I added the "delay(2000);" a member of CEF told me that it would work but I have had no luck with it.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Mar 23, 2008 9:35 pm Post subject: |
|
|
| Code: | #include <iostream>
int main()
{
std::cout << "Hello User!" << " My name is JCoA\n" << "There are many things that I can help you with\n" << "I can do things such as: \n" << "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
std::cin.sync();
std::cin.ignore();
return 0;
} |
If you want a delay, #include <windows.h> and use the Sleep API
_________________
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Mar 23, 2008 10:10 pm Post subject: |
|
|
Also, in case you didn't notice, he dropped your system("pause") command, and replaced it with a much better way of doing it.
If you want to know why it's so bad, Gewgle is your friend.
_________________
|
|
| Back to top |
|
 |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2220
|
Posted: Sun Mar 23, 2008 10:22 pm Post subject: |
|
|
Thanks guys, another question I have is how would I include two headers in 1 script so I can write things onto the screen with the iostream.h header and use the sleep API with windows.h
(I'm fairly new to C++)
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Sun Mar 23, 2008 10:34 pm Post subject: |
|
|
| Negima wrote: | Thanks guys, another question I have is how would I include two headers in 1 script so I can write things onto the screen with the iostream.h header and use the sleep API with windows.h
(I'm fairly new to C++) |
| Code: |
#include <iostream>
#include <windows.h>
//rest of your code here
|
_________________
|
|
| Back to top |
|
 |
Negima I post too much
Reputation: 6
Joined: 22 May 2007 Posts: 2220
|
Posted: Sun Mar 23, 2008 10:43 pm Post subject: |
|
|
Then why won't this work:
| Code: | #include <iostream.h>
#include <windows.h>
int main(void)
{
cout << "Hello User!" " My name is JCoA\n" "There are many things that I can help you with\n" "I can do things such as: \n" "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
sleep(2000);
system("pause");
return 0;
}
|
I keep getting an error in line 7 known as line undeclared
|
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Sun Mar 23, 2008 11:19 pm Post subject: |
|
|
| Negima wrote: | Then why won't this work:
| Code: | #include <iostream.h>
#include <windows.h>
int main(void)
{
cout << "Hello User!" " My name is JCoA\n" "There are many things that I can help you with\n" "I can do things such as: \n" "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
sleep(2000);
system("pause");
return 0;
}
|
I keep getting an error in line 7 known as line undeclared |
Iono if that may be the error...
But, you have no included in that code "using namespace std;"
so cout, would be std::cout
_________________
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Mar 24, 2008 7:54 am Post subject: |
|
|
| Negima wrote: | Then why won't this work:
| Code: | #include <iostream.h>
#include <windows.h>
int main(void)
{
cout << "Hello User!" " My name is JCoA\n" "There are many things that I can help you with\n" "I can do things such as: \n" "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
sleep(2000);
system("pause");
return 0;
}
|
I keep getting an error in line 7 known as line undeclared |
1. You're not including the std namespaces to gain cout's function so for one you have to replace it with std::cout
2. Your Breaking your strings and putting a new string, either make it one full string or add << between strings (like i used for the first reply)
3. C++ is CASE SENSITIVE! the API's name is Sleep not sleep
4. Don't use system("pause"), you have so much else that you could use
std::cin.sync();
std::cin.ignore();
-------------------
(conio.h) _getch();
-------------------
(tchar.h) gettchar();
-------------------
etc.
Should Look like this
| Code: | #include <iostream>
#include <windows.h>
int main()
{
std::cout << "Hello User!" << " My name is JCoA\n" << "There are many things that I can help you with\n" << "I can do things such as: \n" << "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
Sleep(2000);
std::cin.sync();
std::cin.ignore();
return 0;
} |
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Mon Mar 24, 2008 8:14 am Post subject: |
|
|
1. <iostream> not <iostream.h>
2. std::cout
3. | Code: | sleep(2000);
system("pause"); |
(also it should be Sleep, CAPITAL S)
is a gross way to do it, use this instead:
| Code: |
std::cin.sync();
std::cin.ignore(); |
4. Your cout is all broken up needlessly, though I don't think it will really care. Why do things wrong when you can be right, though.
e: and I got the shit beat out of me because I didn't read the topic.
|
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Mon Mar 24, 2008 8:16 pm Post subject: |
|
|
| lurc wrote: | | Negima wrote: | Then why won't this work:
| Code: | #include <iostream.h>
#include <windows.h>
int main(void)
{
cout << "Hello User!" " My name is JCoA\n" "There are many things that I can help you with\n" "I can do things such as: \n" "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
sleep(2000);
system("pause");
return 0;
}
|
I keep getting an error in line 7 known as line undeclared |
1. You're not including the std namespaces to gain cout's function so for one you have to replace it with std::cout
2. Your Breaking your strings and putting a new string, either make it one full string or add << between strings (like i used for the first reply)
3. C++ is CASE SENSITIVE! the API's name is Sleep not sleep
4. Don't use system("pause"), you have so much else that you could use
std::cin.sync();
std::cin.ignore();
-------------------
(conio.h) _getch();
-------------------
(tchar.h) gettchar();
-------------------
etc.
Should Look like this
| Code: | #include <iostream>
#include <windows.h>
int main()
{
std::cout << "Hello User!" << " My name is JCoA\n" << "There are many things that I can help you with\n" << "I can do things such as: \n" << "\n" "-Multiply\n" "-Divide\n" "-Add\n" "-Subtract\n";
Sleep(2000);
std::cin.sync();
std::cin.ignore();
return 0;
} |
|
I did wonder why he did those strings "jump" i means, without the <<. But i did wanted to test, and the way he have it, works perfectly.
_________________
|
|
| Back to top |
|
 |
|