Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,234 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,664 people online right now. Registration is fast and FREE... Join Now!




Temperature Conversion

2 Pages V  1 2 >  
Reply to this topicStart new topic

Temperature Conversion

c++izhere
12 Mar, 2007 - 08:20 PM
Post #1

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
im having alot of trouble with this one because im very new to writing program. please help..

here's the problems:1) Im supppose to write a program to generate a table of conversions from Fahrenheit to Celsius for values from 0 degrees F to 100 degrees F. But print a line in the table for each 5-degree change. using a while loop

2) " " then the same with F to Kelvin for values 0 to 200 degrees F. but this time allow users to enter the increment in degrees F between the lines. using a do loop

3) " " the same with Celsius to Rankin. Allow user to enter the starting temperature and increment between lines. then print 25 lines in the table. using a for loop..

I have to put all of this in 1 single program.. and for 1 im having trouble doing them one by one please help me.
I really want to be efficient at this..i love computers..


Is there somewhere where i can practice this like for instance a "program" like Microsoft Visual C++

This post has been edited by c++izhere: 12 Mar, 2007 - 08:22 PM
User is offlineProfile CardPM
+Quote Post

rizwans
RE: Temperature Conversion
12 Mar, 2007 - 09:00 PM
Post #2

New D.I.C Head
*

Joined: 26 Oct, 2005
Posts: 25


My Contributions
here's a suggestion that has helped memany times over
begin an algorithm design first rather than just starting to code.
it will save you a lot of time and hassle later.
reread the problem 5 times over before even starting to write on paper
then do a step by step algorithm and break each step down into smaller steps
trust me. this will help you out a lot.
you have to put a bit of effort before posting. don't worry though people will help you out for sure. i've received help but i've first had to do something first.
If you're first starting out in c++, go back to basics.
don't use Microsoft Visual c++
use something like borland c++ compiler
or if your school has their compiler use it.
it will help you out later on in the course
User is offlineProfile CardPM
+Quote Post

c++izhere
RE: Temperature Conversion
12 Mar, 2007 - 09:08 PM
Post #3

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
thanks i really appreciate it... hpow do i go about writing the steps you mention.

i think i figured out how to write the first would this be correct for 1):

#include <iostream>
using name space std.
int main()
{
int = a;
a= 0;
while (a<=100)
{
printf ("%4d degrees F= %4d degrees c\n";
a, (a-32) * (5/9);
a= a+10;
}
return 0;
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Temperature Conversion
12 Mar, 2007 - 09:10 PM
Post #4

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
The C++ compiler on this page has had good reviews for being very easy to use.

http://www.bloodshed.net/download.html

I have not used it because I don't have an MS Windows environment set up at home right now, but it can't hurt to download it and try it.

User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Temperature Conversion
12 Mar, 2007 - 09:22 PM
Post #5

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
Rizwans said it correctly.
You need to understand the problem first, then design the algorithm.
And then start the coding.
Now as you are going to use C++ and it is an OO Language, I guess you will be supposed to use classes and methods etc.
So think about it.
Then think about the member functions and the functionality [processing] they will be doing. the steps involved in the process.
etc.

By doing this once, you will get full view of your solution and the coding will be fast and less errorprone...

Hope this will help you... smile.gif
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Temperature Conversion
12 Mar, 2007 - 09:24 PM
Post #6

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
Here is your program without the compile time errors, there are still plenty of logic errors (runtime errors). Pretty good for a first try.
CODE

#include <iostream>

using namespace std;

int main()
{
  int a;
  a = 0;
  while (a <= 100)
  {
    printf ("%4d degrees F = %4d degrees c\n");
    a = ( a - 32) * (5 / 9);
    a = a + 10;
  }
  return 0;
}


User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Temperature Conversion
12 Mar, 2007 - 09:59 PM
Post #7

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
QUOTE(ajwsurfer @ 13 Mar, 2007 - 10:54 AM) *

Here is your program without the compile time errors, there are still plenty of logic errors (runtime errors). Pretty good for a first try.
CODE

#include <iostream>

using namespace std;

int main()
{
  int a;
  a = 0;
  while (a <= 100)
  {
    printf ("%4d degrees F = %4d degrees c\n");
    a = ( a - 32) * (5 / 9);
    a = a + 10;
  }
  return 0;
}




Well that's something which happens when you code even before you decide what exactly you want to code... smile.gif

See there are no runtime errors in programs, they are simple logical bugs.

like....
* you are printing (user "cout: you are in c++ now) but where are the variables to print?

* If you modify a like that then it will never satisfy the while condition. [atleast it will not give you the expcted output].

* Using Integer??? are you sure that you will not need to store the floats?

I am not trying to criticise you but I just want to say that please give a thought to the process and algorithm and you will be benifited...

Well, I don't like to code like this but I have modified your code for you.
Just have a look, but please follow the rules. This is not the right way of coding.

CODE


#include <iostream>

using namespace std;

int main()
{
  
    float a,b;
  a = 0;
  while (a <= 100)
  {
    
    b = ( a - 32) * (5 /(float) 9);
    a = a + 5;    
    cout<<a<<" degrees F = "<<b<<" degrees celcius."<<endl;
  }
  return 0;
}




hope this will help you... smile.gif
User is offlineProfile CardPM
+Quote Post

c++izhere
RE: Temperature Conversion
12 Mar, 2007 - 10:18 PM
Post #8

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
thanks i used your help and my program says i have an error saying it expected ';' before "a" how do I fix that
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Temperature Conversion
12 Mar, 2007 - 10:22 PM
Post #9

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
QUOTE(c++izhere @ 13 Mar, 2007 - 11:48 AM) *

thanks i used your help and my program says i have an error saying it expected ';' before "a" how do I fix that


now you missed some ";" somewhere...
will you post the code please?
User is offlineProfile CardPM
+Quote Post

c++izhere
RE: Temperature Conversion
12 Mar, 2007 - 10:29 PM
Post #10

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
i found the problem i was missing a ;...after i fixed it and tried to run/execute the window just flashes
User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Temperature Conversion
12 Mar, 2007 - 10:50 PM
Post #11

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
QUOTE(c++izhere @ 13 Mar, 2007 - 11:59 AM) *

i found the problem i was missing a ;...after i fixed it and tried to run/execute the window just flashes


smile.gif I guess you are working in VC++...
well put the code on, just to check incase if it has any problems.
but putting cin>>ch, [getch() in C] kind of statement will solve it.

User is offlineProfile CardPM
+Quote Post

c++izhere
RE: Temperature Conversion
14 Mar, 2007 - 01:55 PM
Post #12

New D.I.C Head
*

Joined: 12 Mar, 2007
Posts: 41


My Contributions
MAY SUM 1 HELP ME WITH THE OTHER 2, BECAUSE I STILL HAVE TO COMBINE THEM INTO 1 PROGRAM, IM GETTING BETTER AT IT BUT I NEED HELP FROM EXPERIENCE USERS.. HELP ME...THANKS TO ALL WHO'VE HELPED ME ALREADY I REALLY APPRECIATE IT, YOU GUYS ARE HELPING GET BETTER AT THIS....
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/4/08 03:59PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month