Hey everyone. I'm attempting to write a code that will display the distance between two rooms. I have most of the program correct, I just can't figure out how to display the names of the rooms by their actual names (ie. Room C123.7) rather than with just a number. I have JUST begun learning about arrays, and strings, so it is confusing me. My work so far is shown below. Any help or tips are appreciated! I'm new to C++, and have been teaching myself, so I am sure I am making quite a few mistakes. Thank you!
1 2 3 4 5 6 7 8
|
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
int main ()
|
1 2
|
{
double length_in_feet = 0;
|
// Variable for length in feet. Globally initialized
1 2
|
{
double length_in_meters = 0;
|
// Variable for length in meters locally initialized
1 2
|
double sum = 0;
const double constant = 3.2808;
|
// Constant for meters to feet conversion locally initialzed
char indicator = 'y';
// Loop as long as 'yes' is entered
while(indicator == 'y')
// Loop as long as 'yes' is entered
1 2 3 4
|
{
cout << "Enter measured length in meters"
<< endl;
cin >> length_in_meters;
|
// Enter measured length of wire
1 2 3 4
|
sum += length_in_meters;
cout << endl
<< "Is there another cable length for you to enter? (enter y to enter another)? ";
cin >> indicator;
|
// Read the indicator
1 2 3
|
}
length_in_feet = sum * constant;
|
// Conversion from meters to feet
cout << "Your length is " << length_in_feet << " in feet"
// Output in feet
1 2 3 4 5 6 7 8 9
|
<< endl << endl;
}
{
const char MAX = 100;
char location_1 [MAX];
cout << "Enter the room and rack where the cable begins.";
cin.getline(location_1, MAX);
|
// Location where cable begins
1 2 3 4 5 6 7 8 9
|
}
{
const char MAX = 100;
char location_2 [MAX];
cout << "Enter the room and rack where the cable ends.";
cin.getline(location_2, MAX, '\n');
|
// Location where cable is terminated
1 2 3 4 5 6 7 8
|
}
{
const char MAX = 100;
char cable_type [MAX];
cout << "Enter the type of cable being used.";
cin.getline(cable_type, MAX, '\n');
|
// Type of cable being used
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
}
{
const char MAX = 100;
char location_1 [MAX];
char location_2 [MAX];
char cable_type [MAX];
cout << "The distance between " << location_1 << " and " << location_2 << " is " << length_in_feet << " using " << cable_type << " cable.";
}
return 0;
}
|