| View previous topic :: View next topic |
| Author |
Message |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 4:12 pm Post subject: Need help! |
|
|
I place this and compile it
#include <iostream>
using namespace std;
int main() {
double ctemp,ftemp;
cout<<"Input a Celcius temp and press ENTER: ";
cin>>ctemp;
ftemp = (ctemp * 1. + 32;
cout<<"Farenheit temp is: "<<ftemp;
return 0;
}
wen i finish compiling it i place a number and press enter but it doesnt come up with the answer.
This is converting celcius to farenheit.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Oct 21, 2007 4:25 pm Post subject: |
|
|
#Include <conio.h>
and place getch(); at the end. works for me... always worked in my noobie C++ programs
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Oct 21, 2007 4:30 pm Post subject: |
|
|
| Code: | #include <iostream>
#include <conio.h>
using namespace std;
int main()
{
double cTemp, fTemp;
cout << "Input a Celsius temperature: ";
cin >> cTemp;
fTemp = (double)((cTemp * 1.8) + 32);
cout << "The Farenheit temperature is: " << fTemp;
_getch();
return 0;
} |
|
|
| Back to top |
|
 |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 4:42 pm Post subject: |
|
|
| Wiccaan wrote: | | Code: | #include <iostream>
#include <conio.h>
using namespace std;
int main()
{
double cTemp, fTemp;
cout << "Input a Celsius temperature: ";
cin >> cTemp;
fTemp = (double)((cTemp * 1.8) + 32);
cout << "The Farenheit temperature is: " << fTemp;
_getch();
return 0;
} |
|
Thanks but y does it work that way other then the way i did it?
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Oct 21, 2007 4:57 pm Post subject: |
|
|
don't use __getch()
why?
you have to include more headers = more program size
why use 1 thing when another works just as well being more effecient
use
cin.ignore();
cin.get();
_________________
|
|
| Back to top |
|
 |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 5:02 pm Post subject: |
|
|
| I tried that but it doesnt work.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Oct 21, 2007 5:11 pm Post subject: |
|
|
| Code: |
#include <iostream>
using namespace std;
int main()
{
double cTemp, fTemp;
cout << "Input a Celsius temperature: ";
cin >> cTemp;
fTemp = (double)((cTemp * 1.8) + 32);
cout << "The Farenheit temperature is: " << fTemp;
cin.ignore();
cin.get();
return 0;
}
|
are you dumb, that works o.o
_________________
|
|
| Back to top |
|
 |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 5:16 pm Post subject: |
|
|
| blankrider wrote: | | Code: |
#include <iostream>
using namespace std;
int main()
{
double cTemp, fTemp;
cout << "Input a Celsius temperature: ";
cin >> cTemp;
fTemp = (double)((cTemp * 1.8) + 32);
cout << "The Farenheit temperature is: " << fTemp;
cin.ignore();
cin.get();
return 0;
}
|
are you dumb, that works o.o |
My bad i thought u meant only 1 of them. sry.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Oct 21, 2007 6:34 pm Post subject: |
|
|
Lol more size just for including <conio.h>?
Debug build with default compiler settings (without include): 44k
Debug build with default compiler settings (with include): 44k
HUGE difference.
|
|
| Back to top |
|
 |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 6:44 pm Post subject: |
|
|
| Why is my way wrong? Its on an internet tut.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Oct 21, 2007 6:56 pm Post subject: |
|
|
when you get into bigger libraries you can be having 10k size difference. So why get into a bad habit now?
i actually just wrote a program in directx and excluded a library and shaved 10kb off my program.
and dont make debug builds, your adding like 20k to your program size.
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Oct 21, 2007 7:19 pm Post subject: |
|
|
| Hackerdevelopment wrote: | | Why is my way wrong? Its on an internet tut. |
Your method does work, its just not stopping the window from closing after outputting. So you just never see the output before it closes. If you run it through dos you will see the output without the window closing.
| blankrider wrote: | when you get into bigger libraries you can be having 10k size difference. So why get into a bad habit now?
i actually just wrote a program in directx and excluded a library and shaved 10kb off my program.
and dont make debug builds, your adding like 20k to your program size. |
Can I ask how you are trying to compare file sizes when you are referring to something different then the include in question? Yes, some things can cause the file size to incase, but just because you are adding more code around it doesn't make that include the fault of the increase. conio is a very standard include with basic functions that causes little to no increase in the compiled output.
As for 'dont make debug builds'. Theres a reason for them. I know it adds to the file size, theres a reason for that as well.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sun Oct 21, 2007 7:37 pm Post subject: |
|
|
would you RELEASE the debug build
no!
so you should relate file size to the release build
and you shouldn't include headers you don't need, its just bad practice and will affect you in larger projects.
maybe conio doesn't affect file size, but its bad practice, so you should try to kick those habits.
its like walking through a puddle, you use more energy when you go around it.
if that made any sense.
Please don't qoute me on that and try to say that doesn't relate to programming. Someone will try that, they always do. If you don't see the relation, you are dumb. (not directing that at you wiccan)
_________________
|
|
| Back to top |
|
 |
Hackerdevelopment Advanced Cheater
Reputation: 0
Joined: 11 Oct 2007 Posts: 55
|
Posted: Sun Oct 21, 2007 8:20 pm Post subject: |
|
|
[quote="Wiccaan"] | Hackerdevelopment wrote: | | Why is my way wrong? Its on an internet tut. |
Your method does work, its just not stopping the window from closing after outputting. So you just never see the output before it closes. If you run it through dos you will see the output without the window closing.
thanks a lot. It actually worked with the dos.
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Oct 21, 2007 8:21 pm Post subject: |
|
|
| blankrider wrote: | would you RELEASE the debug build
no!
so you should relate file size to the release build
and you shouldn't include headers you don't need, its just bad practice and will affect you in larger projects.
maybe conio doesn't affect file size, but its bad practice, so you should try to kick those habits.
its like walking through a puddle, you use more energy when you go around it.
if that made any sense.
Please don't qoute me on that and try to say that doesn't relate to programming. Someone will try that, they always do. If you don't see the relation, you are dumb. (not directing that at you wiccan) |
How is conio bad practice? It's what the file was made for, console input and output. (Hence the name conio.)
My quote above was because you compared a lib to an include.
| Quote: | | i actually just wrote a program in directx and excluded a library and shaved 10kb off my program. |
A lib and an include are two separate things. You shaved size off because you were statically compiling the lib into your program. Yes, some includes also add libs to the compiled project, but, not all of them do.
If you wish to say something is bad practice, using conio over iostream would be the better choice. iostream includes a whole bunch more things you will never use for simple projects like the one above, where as conio will simply only do the basics. If you want to decrease the size the most:
| Code: | #include <conio.h>
int main()
{
char szBuffer[255] = {80};
char *szReturn;
_cprintf("Please enter your name: ");
szReturn = _cgets(szBuffer);
_cprintf("Thank you, %s", szReturn);
_getch();
return 0;
} |
Just use conio itself to do all your console input and output.
The end result:
Debug Mode (Standard Config Settings): 40kb
Release Mode (Standard Config Settings): 5.5kb
Using iostream:
| Code: | #include <iostream>
using namespace std;
int main()
{
char szBuffer[255] = {0};
printf("Please enter your name: ");
cin.get(szBuffer, sizeof(szBuffer));
printf("Thank you, %s", szBuffer);
cin.ignore();
cin.get();
return 0;
} |
The end result:
Debug Mode (Standard Config Settings): 40kb
Release Mode (Standard Config Settings): 6.0kb
The change isn't huge, but, as you can see iostream adds more.
|
|
| Back to top |
|
 |
|