I just recently started a class for programming with C and I'm stuck on an assignment. I don't have my textbook yet so what I've done so far on this assignment is based off of tutorials i found on the internet.
Here's the assignment problem: Write a C program, speed.c, which performs the following operations (be sure to give all numeric output
to two decimal places).
1. Assigns a value (425.5) representing the distance in miles traveled by a car
2. Assigns a value (7.5) representing the number of hours taken to travel that distance
3. Computes the speed of the car in miles/hour (speed = distance / time)
4. Computes the speed of the car in meters/second (use 1 mile = 1600 meters)
I took a class on C for a few weeks so I still remember a couple things, however, i ran into a few problems but here is the code I've came up with.
/***********************************************************************
Design:
1. Declare Variables for distance traveled, hours taken to travel the distance, speed in miles per hour and speed in meters per second.
2. Assign values to the variables
3. Calculate the speed of the car in miles per hours using the Speed formula.
4. Convert Miles per hour to Meters per second.
5. Display results to user.
**********************************************************************/
#include <stdio.h>
int main();
{
//Declaring Variables
float distance_traveled, hours_taken;
float speed_mph, speed_mps;
distance_traveled = 425.5;
hours_taken = 7.5;
// Calculations for speed (miles/hour)
distance_traveled / hours_taken = speed_mph
//Converting miles per hour to meters per second (1 mile = 1600 meters, 7.5 hours = 27000 seconds
distance_traveled x 1600 / 27000 = speed_mps
//Display output to user for miles traveled
printf("You traveled %f miles\n", 425.5)
//record information to csis.txt file
fprintf(csis, "You traveled %f miles", 425.5)
//Display output to user for hours traveled
printf("You traveled for %f hours\n", 7.5)
//record informatioin to csis.txt file
fprintf(csis, "You traveled for %f hours\n", 7.5)
//Display output to user for miles an hour and meters per second
printf("You traveled at %f mph or %f meters per second\n", speed_mph, speed_mps)
return 0;
}
Now i know that there's probably lots of errors in there, but i just need some help figuring out what i'm doing incorrectly.
Also, whenever i try to do the "Hello World" program to just try to build a program, it gives me an error on the last "}" on the bottom of the page, saying that it expects a variable declaration.

New Topic/Question
Reply


MultiQuote




|