ok i'm writing some code for my cs class but i'm getting errors i think shouldn't be there. it builds, but when i debug i get "distkilo is used without being defined". will someone compile the code below and let me know if it works? using vc++ .net if that helps. thanks.
<pre>
#include <iostream.h>
int CalcDistance(int, int);
int CalcKilometers(int);
int main(void)
{
// Declarations of 4 variables with comments for each
int dist; // integer variable for distance
int rate; // integer variable for rate (speed)
int time; // integer variable for time
int distkilo; //integer variable for distance in kilometers
// Initialization of speed and time elapsed
cout << "Enter the speed of travel (in mph): ";
cin >> rate;
cout << "Enter the time traveled: ";
cin >> time;
dist = CalcDistance(rate, time); // find the distance
distkilo = CalcKilometers(dist); // convert to kilometers
// Print values of 4 variables
cout << "The values found were:nn";
cout << "Distance (in miles) = " << dist << "n";
cout << " (in kilometers) = " << CalcKilometers(dist) << "n";
cout << "nSpeed = " << rate;
cout << "nTime = " << time;
cout << "n";
cin.get(); cin.get();
return 0;
}
/*
function to calculate distance
pre: rate and time are integers
post: distance is returned
*/
int CalcDistance(int rate, int time)
{
return (rate * time);
}
/*
function to convert miles to kilometers
pre: dist is an integer
post: distance in kilometers is returned
*/
int CalcKilometers(int dist)
{
return (dist * 1609 / 1000);
}
</pre>
Question
caustiK
ok i'm writing some code for my cs class but i'm getting errors i think shouldn't be there. it builds, but when i debug i get "distkilo is used without being defined". will someone compile the code below and let me know if it works? using vc++ .net if that helps. thanks.
Link to comment
Share on other sites
4 answers to this question
Recommended Posts