Old 01-07-2008, 03:14 AM   #1 (permalink)
Banned
 
Join Date: Jul 2006
Posts: 3,142
Reputation: 101
Default help please.

Code:
#include  <iostream.h>

int main(void)
{
    int       DegreeF = 41;
    float     DegreeC = .55;
    DegreeC= (DegreeF-32);
    cout << "Fehreinhiet to Celsius = ";
    cout << DegreeC;
    cout << '\n';
}
i can complile and run this program, but as soon as the program shows up it closes it self. i have copied other scripts character per character and i have the same problem. i'm not sure what to do; care to help?

Last edited by bonneau_14; 01-08-2008 at 08:00 PM.
bonneau_14 is offline  
Old 01-07-2008, 04:27 AM   #2 (permalink)
Master Chief's Windex
 
SilentSiren's Avatar
 
Join Date: Sep 2006
Location: England
Posts: 80
Reputation: 10
Send a message via MSN to SilentSiren
Default

On the last line either put a :

cin
Code:
#include  <iostream.h>

int main(void)
{
    int       DegreeF = 41;
    int       somevar;
    float     DegreeC = .55;
    DegreeC= (DegreeF-32);
    cout << "Fehreinhiet to Celsius = ";
    cout << DegreeC;
    cout << '\n';
    cin >> somevar;
}
that will wait for some input before closing or

or as long as you include the windows.h file you can use

sleep(x)
Code:
#include  <iostream.h>
#include  <windows.h>

int main(void)
{
    int       DegreeF = 41;
    float     DegreeC = .55;
    DegreeC= (DegreeF-32);
    cout << "Fehreinhiet to Celsius = ";
    cout << DegreeC;
    cout << '\n';
    sleep(5);
}
where x is the amount of time to send the program to sleep before continuing

There are other more efficient and standardized ways of doing so but the above two will both work and are relatively straight forward.
__________________
.::.SilentSiren.::.
Head of Blood on Binary.
Lead Developer of Escalation.

Last edited by SilentSiren; 01-07-2008 at 04:31 AM.
SilentSiren is offline  
Old 01-08-2008, 08:01 PM   #3 (permalink)
Banned
 
Join Date: Jul 2006
Posts: 3,142
Reputation: 101
Default

Code:
#include  <iostream.h>

int main(void)
{
    int       DegreeF = 41;
    int       somevar;
    float     DegreeC = 1.8;
    DegreeC= (DegreeF-32);
    cout << "Degrees in Fahrenheit = ";
    cout << DegreeF;
    cout << '\n';
    cout << "41 degrees Fahrenheit is equilvelent to ";
    cout << DegreeC;
    cout << " Celsius";
    cout << '\n';
    cin >> somevar;
}
my new program; when i compile and run it works fine except for it outputting the wrong translation. the out for celsius is 9, it should be 5. i think if i change the formula on line 8 to devide the answer by 1.8 it should make the output be 5. care to help again?

41-32 = 9[divided by]1.8 = 5 degrees celsius.

my program goes to is "41-32 = 9" then it outputs the answer 9

Last edited by bonneau_14; 01-08-2008 at 11:02 PM.
bonneau_14 is offline  
Old 01-08-2008, 10:41 PM   #4 (permalink)
Master Chief's Windex
 
SilentSiren's Avatar
 
Join Date: Sep 2006
Location: England
Posts: 80
Reputation: 10
Send a message via MSN to SilentSiren
Default

A Thank You wouldnt go amiss lol.

First of!
Children complain "When will we ever use Algebra?!?" well see below :

DegreeC= (DegreeF-32); where DegreeF = 41 so if we convert it all into numbers:-

1.8 = (41-32)

So its inefficient as your formula isnt complete or making much sense.

Typically you only use variable replacements for numbers in your code if it is going to be large if it is small like this you could just forget the vars and use the numbers but for the sake of good programming here is how it should look based on your suggested formula:

As a note if you use floating variables then you should store results in a floating type in my opinion memory at this level isnt much of a biggy.

Code:
#include  <iostream.h>

int main(void)
{
    int       DegreeF = 41;
    int       adjust = 32;
    int       somevar;
    float     DegreeC = 1.8;
    float     Result;
    Result = (DegreeF-adjust)/DegreeC;
    cout << "Degrees in Fahrenheit = ";
    cout << Result;
    cout << '\n';
    cout << 'DegreeF';
    cout << " degrees Fahrenheit is equilvelent to ";
    cout << Result;
    cout << " Celsius";
    cout << '\n';
    cin >> somevar;
}
__________________
.::.SilentSiren.::.
Head of Blood on Binary.
Lead Developer of Escalation.
SilentSiren is offline  
Old 01-08-2008, 11:17 PM   #5 (permalink)
Banned
 
Join Date: Jul 2006
Posts: 3,142
Reputation: 101
Default

thank you! i meant to put that in my post above but i got distracted before finishing it. I am quite aware that i'll need algebra--i knew that before i started to learn how to script. in two and a half years i'm going to post-secondary school to become a computer programmer; i thought if i knew C++ school would be a bit easier.

this is a exercise at the end of a chapter in a book and it wants me to use this formula: so i put the 1.8 where the 5/9 is and i get a error and it won't compile.but i can see there are some extra steps i need to do in order for it to work. I am sorry for the delayed thank you; you have my gratitude.

EDIT: when i edited my code with your edit something didn't work right; i got some random 12 digit number. but i have resolved the problem. and again i thank you, now i can move on in the book.

Last edited by bonneau_14; 01-08-2008 at 11:27 PM.
bonneau_14 is offline  
Old 01-17-2008, 06:43 PM   #6 (permalink)
Still learning the ropes
 
The Pig's Avatar
 
Join Date: Jan 2008
Posts: 27
Reputation: 10
Default

Man thats confusing....i wish i knew programmming. Whats the easiest way to learn the basics?
The Pig is offline  
Old 01-17-2008, 11:02 PM   #7 (permalink)
Crumbly, but Good
 
Eriond's Avatar
 
Join Date: May 2006
Location: Montreal
Posts: 1,646
Reputation: 67
Send a message via MSN to Eriond
Default

Easiest way to start is to take a course, to get the basics. I found that really helped. But you can do it online, it's not that much harder, especially if you have someone (I.E. this forum) you can ask when you need help. Check out this thread if you want to get started:
http://www.onrpg.com/boards/1215.html
__________________
Outsider
3D Space Action Shooter/RPG in Development
http://www.youtube.com/user/outsidergame
Eriond is offline  
Old 01-19-2008, 11:09 AM   #8 (permalink)
Dixie Banana Bar
 
Arakys's Avatar
 
Join Date: Dec 2007
Posts: 276
Reputation: 10
Default

I'm attending computer science university and i can easily tell yuo all that teachers actually DID NOT TEACH YOU ANYTHING thay just stay there talking about frayed air for 4. .. 5 even 7 hours 'bout programming ethics . Then at the end of the course they ask you to implement a huge system from nothing.

So , actually, in my opinion the milestone from which i've started learning about programming is

" C Language" of Kernighan & Ritchie and then if you want to move to any other lenguage just buy a reference manual ..
__________________
" Here we go our step so silent
Here we go our blooded trace
the Jester Race "


http://mjalkar.mybrute.com
Arakys is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:20 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0
OnRPG, Copyright ©2003-2011, Game Entertainment Enterprises