2 Replies - 1343 Views - Last Post: 01 February 2015 - 08:59 PM Rate Topic: -----

#1 mgfleezus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 15

Need help on a easy homework assignment, asap

Posted 01 February 2015 - 07:35 PM

Hi there,

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help on a easy homework assignment, asap

#2 jon.kiparsky   User is offline

  • Beginner
  • member icon


Reputation: 12350
  • View blog
  • Posts: 20,984
  • Joined: 19-March 11

Re: Need help on a easy homework assignment, asap

Posted 01 February 2015 - 07:38 PM

You don't seem to have quite as many semicolons there as I'd expect in a program with that many instructions. :)
Was This Post Helpful? 0
  • +
  • -

#3 mgfleezus   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-February 15

Re: Need help on a easy homework assignment, asap

Posted 01 February 2015 - 08:59 PM

View Postjon.kiparsky, on 01 February 2015 - 07:38 PM, said:

You don't seem to have quite as many semicolons there as I'd expect in a program with that many instructions. :)/>


Okay, thanks! Besides that, anything else that is worth noting? Does the format make sense?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1