In my opinion, most programmers can't write a complete program then put in their calculations and have it work the first time. Do the math portion first, Then do the output section, and you'll know what the user input variables should be. T
In convertYards you want to get the value from another function, so you can pass the value or make a global value.
In this case, when the user enters a distance, I would convert that to feet. Pass feet to convertYards.
Once you have the distance in feet, it's easy to convert to yards or miles.
Otherwise, if you add distance 1 and 2, and the values are 59, 59, 59 you have a hard time converting 118 miles 118 yards and 118 feet into anything.
if A add the distances and then convert
if B 60 miles per hour = 88 feet per second.
To me it looks like you have a lot of things to fix in your code.
If I was doing this, I would start simple, get the math working, get the output looking like I wanted, and then add the user input.
Sorry i can't help but play with examples when I'm thinking about a problem. Hope this is helpful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int yards=1760;
int feet=5280;
int UserInputFeet=5287;
int TimeinMins=60;
int x=0; // Miles
int y=0; // Yards
int r=0; // Remainder
void convert()
{
x=UserInputFeet/feet; // Miles traveled
r=(UserInputFeet-(x*feet));
y=r/3; // Yards
r=(UserInputFeet-(x*feet));
r=(r-(y*3)); // Feet
}
void Report()
{
cout << " Miles Traveled " << x << endl;
cout << " Yards Traveled " << y << endl;
cout << " Feet Traveled " << r << endl; // Feet traveled
cout << " User traveled " << x << " Miles " << y << " Yards " << r << " Feet in " << (TimeinMins/60) << " hour" << endl;
cout << " User traveled " << UserInputFeet << " Feet in " << TimeinMins << " Mins" << endl;
cout << " User traveled " << UserInputFeet << " Feet in " << (TimeinMins*60) << " Seconds" << endl;
}
int main()
{
convert ();
Report();
return 0;
}
|