I need help To comment this program for my college work

#include <stdio.h>

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

Dani AI

Generated

Notes to help comment and improve the posted Fahrenheit-to-Celsius program (original by ). As noted, the code is written in C, so a college-style submission should include a short header block, brief algorithm notes, and inline comments that explain each step.

/*
 Program: Fahrenheit to Celsius table
 Author: Your Name
 Purpose: Print F->C values from 0 to 300 every 20 degrees.
 Inputs: none
 Outputs: formatted table of Fahrenheit and Celsius values
 Algorithm: loop over Fahrenheit values, apply conversion (F - 32) * 5/9
 Notes: original used integer math (truncates); use floating point for decimals
 Compile: gcc -std=c99 -Wall -Wextra -o f2c f2c.c
*/

Key point: integer division. In the posted expression (a - 32) * 5 / 9 all operands are integers, so the result is truncated. Force floating-point arithmetic to keep fractions, e.g.:

printf("%4d F = %6.2f C\n", a, (a - 32.0) * 5.0 / 9.0);

See the Celsius/Fahrenheit relation and printf details at .

Small quality tips: use named constants (MIN_F, MAX_F, STEP), prefer a for loop for a fixed-range table, enable -Wall -Wextra, and test boundary values (0, 32, 100, 212). Common student questions (mentioned by and ) are the role of a, the loop bounds and step, arithmetic order, and the printf format string — cover each in one-line inline comments so graders can see understanding.

Recommended Answers

All 3 Replies

That is a C program, not C++. What parts don't you understand ?

What help u want from this program.....

wat do u dont understand???

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.