This is my first post, and I'm VERY new to C++, but I just finished my first class, and upon requesting the final, I was told to re-do one of my programs, because instead of computing the values, I just displayed them. (It never said I needed to.) Now that I re-did it, it dosent seem to be working, and displays a '0' in the 'celsius column. (My program computes and displays a chart of Fahrenheit and Celsius temperatures. Perhaps you can see an error that I don't? (Also, please use the simplest terms possible, I'm really new to this.)

/* File: celFar.cpp
*  -------------------
*  This file computes and displays the table of 
*  farenheit and celsius temperatures 0-200.
*/

#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#include <math.h>
#include "strlib.h"





int main()
{
	
	double num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11


		;num1=((5/9)*(0-32))
		;num2=((5/9)*(20-32))
		;num3=((5/9)*(40-32))
		;num4=((5/9)*(60-32))
		;num5=((5/9)*(80-32))
		;num6=((5/9)*(100-32))
		;num7=((5/9)*(120-32))
		;num8=((5/9)*(140-32))
		;num9=((5/9)*(160-32))
		;num10=((5/9)*(180-32))
		;num11=((5/9)*(200-32))



		;printf("Farenheit	Celsius\n0		%.1g	\n20		%.1g	\n40		%.1g	\n60		%.1g	\n80		%.1g	\n100		%.1g	\n120		%.1g	\n140		%.1g	\n160		%.1g	\n180		%.1g	\n200		%.1g	\n",num1,num2,num3,num4,num5,num6,num7,num8,num9,num10,num11)

;}

I am sorry but I laughed! However, we all begin somewhere. I can't say my early stuff was any good. [having said that I am not sure what I write today is that good.]

First off: the ; (semi-colon) is a statement end. It doesn't actually
matter were you put it, but it is extremely usual to put it at the end of the line. eg.
num1=(5/9)*32;
The white space (spaces and newline) don't matter.

So I am assuming that you haven't looked at any kind loops yet, or this program would score rather lowly.

But your program has been hurt by the fundamentals of computing, ie that it is difficult to represent numbers. Numbers in C++ can be integers / double / float and others. Each type of number has specific rule on the mathematics. In this case,

the line num5=((5/9)*(80-32)); is the same as num5=0; because (5/9)=0

The reason is that 5 and 9 are integers and under c++ and many computer languages normal mathematical integer arithmatic applies,
and the result must be in the domain of the problem. So 5/9 can only be an integer.

This can be circumvented in a number of ways. e.g. (5/9.0) or (5.0/9) or casting.

You might have wanted to use an intermediate variable here.
e.g. double factor=5.0/9.0;

Thanks, but I finished it before I got your reply. I understand the laughter, as I made sevweral stupid errors. The program is now complete, and all I need now is the final. To be honest, I'm really tired of this, because i did half of the entire course just yesterday, so I'm really C++'d out!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.