Write a C program to read values for times from the input file?

Click For Summary

Discussion Overview

The discussion revolves around a homework assignment requiring participants to write a C program that reads time values from an input file, computes the sine of those values, and outputs the results to a CSV file. The scope includes programming, file handling, and mathematical computation.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant outlines the homework requirements, including reading from a file, computing sine values, and outputting results in a specific format.
  • Another participant expresses reluctance to provide direct help with the assignment, suggesting that the original poster should attempt the task independently and consult their textbook for guidance.
  • A suggestion is made to provide pseudo code to help structure the program, emphasizing the steps involved in file handling and computation.
  • A later reply indicates that the original poster feels they have received the necessary help.
  • Another participant offers to assist with specific questions or problems that may arise during coding.

Areas of Agreement / Disagreement

There is no consensus on providing complete solutions; participants generally agree that the original poster should attempt the assignment independently while offering guidance and support for specific issues.

Contextual Notes

Participants have not resolved the specifics of the programming task, such as the correct implementation of file handling or the computation of sine values, and there are no detailed code corrections provided.

sheldonrocks97
Gold Member
Messages
66
Reaction score
2

Homework Statement


Write a C program to read values for times from the input file times.txt; compute sin(5*pi*t) for each time t given in times.txt; output comma separated values of t, sin(5*pi*t) into an output file named output.csv; and compile the program using a makefile. Hand in a copy of your program, output file, and makefile.

LIST OF TIMES:

0
0.0121
0.0241
0.0362
0.0483
0.0603
0.0724
0.0845
0.0965
0.1086
0.1207
0.1327
0.1448
0.1569
0.1689
0.1810
0.1931
0.2051
0.2172
0.2293
0.2413
0.2534
0.2655
0.2775
0.2896
0.3017
0.3137
0.3258
0.3379
0.3499
0.3620
0.3741
0.3861
0.3982
0.4103
0.4223
0.4344
0.4465
0.4585
0.4706
0.4827
0.4947
0.5068
0.5189
0.5309
0.5430
0.5551
0.5671
0.5792
0.5913

Homework Equations

The Attempt at a Solution


#include<stdio.h>

#include<math.h>

void main (void)

{

FILE *times.txt, *output.csv; //input/output files//

int t; //time variable//

int x = sin(5*M_PI*t);Please help my friend and I are very very desperate!
 
Physics news on Phys.org
I'm sorry to say that while many of us could easily write this program, we can't in good conscience do it. This is your homework assignment you and your friend need to mount a valiant defense, read your book and just get down and do it. It should take no more than an hour or so to write.

I can show you some pseudo code to follow that may help you get started. Also you can easily find program recipes that read files, convert strings to numbers, compute values and print them out which are the basic things your program needs to do.

Some pseudo code:

Code:
Open file
For each line in the file
{
        Read one number
        Compute sin()
        Print t, comma, sin()
}
Close file

So follow each line and look up in your book for things that match what the line does.
 
Thank you. My friend and I got the help we needed.
 
  • Like
Likes   Reactions: jedishrfu
That's great if you run into specific questions or problems with your code, post it and we can provide some help.