![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 9
Rep Power: 0
![]() |
Two things how do I set it for a console program to not just close after I put in the input. Here the simple program. Also with how float isn't that powerful compared to double how come it takes so long to compile?
#include <stdio.h> #include <iostream.h> int main(int nNumberofArgs, char* pszArgs[]) { float celsius; cout << "Enter the temperature in Celsius:"; cin >> celsius; float factor; factor = 212 - 32; float fahrenheit; fahrenheit = factor * celsius/100 + 32; cout << "Fahrenheit value is:"; cout << fahrenheit; return 0; } |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 5
![]() |
#include <stdio.h>
#include <iostream.h>
int main(int nNumberofArgs, char* pszArgs[])
{
float celsius;
cout << "Enter the temperature in Celsius:";
cin >> celsius;
float factor;
factor = 212 - 32;
float fahrenheit;
fahrenheit = factor * celsius/100 + 32;
cout << "Fahrenheit value is:";
cout << fahrenheit;
cin.get(); // Add this from iostream, or getchar() from stdio.h
return 0;
}#include <stdio.h>
#include <iostream.h>
int main(int nNumberofArgs, char* pszArgs[])
{
float celsius;
cout << "Enter the temperature in Celsius:";
cin >> celsius;
float factor;
factor = 212 - 32;
float fahrenheit;
fahrenheit = factor * celsius/100 + 32;
cout << "Fahrenheit value is:";
cout << fahrenheit;
char ch;
while ( cin.get ( ch ) && ch != '\n' )
;
cin.get(); // Add this from iostream, or getchar() from stdio.h
return 0;
}>how come it takes so long to compile? Sometimes it takes more effort to access a smaller type than a larger one. For example, most machines are byte-addressable, but it's far more efficient to access memory by the word. That's why the generally accepted wisdom is to use int and double as your primary types unless you have very special needs or you know for a fact that your system handles other types more efficiently. However, all of that aside, whether you choose float or double has no real effect on compilation time. That depends on how smart your compiler is (by not recompiling unchanged code) and how many dependencies your code introduces (such as how many headers are included by iostream). |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Oct 2004
Posts: 9
Rep Power: 0
![]() |
Quote:
Also to make that pause, the best way to me is to add system("PAUSE");#include <stdlib.h> |
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 5
![]() |
>Double is much harder on the computer then float.
Prove it. Most processor FPUs do their internal work at double or long double precision, so it's fairly safe to say that double is at least as fast as float, and probably faster because the processor avoids the overhead required to convert from float to double and back again. Of course, float and double could be the same size, in which case they're equivalent. This backs up my claim that double should be used unless there's a good reason not to. >Whenever possible don't use double when you could use float. Perhaps if double is larger than float and you have a large number of them, such as an array then float is a better choice to save space. >Also to make that pause, the best way to me is to add Using system in this way isn't portable and is also a security risk. |
|
|
|
|
|
#5 | |
|
Newbie
Join Date: Nov 2004
Posts: 12
Rep Power: 0
![]() |
[quote]Originally posted by JPPLAY@Nov 21 2004, 06:09 PM
Quote:
Since you only really need to pause on windows, "system("pause");" is an okay solution, just know that it will not work on other systems. Since he is using c++, and not c, the correct c++ header is actually #include <cstdlib> |
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 5
![]() |
>Since he is using c++, and not c, the correct c++ header is actually
At which point, the correct call is: std::system ( "pause" ); |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|