I'm sort of new to c++, I've taken a class over the summer and have gotten to the point of learning about pointers and how to use them. Right now, I'm trying to figure out how to take user input into an array in one Class Function, and then take that and use it in another class function. I'm not worried about anything else in the code right now.
I've tried using seperate variables then setting them equal to i, j, and using various loops to solve the problem but nothing is working so far. The problem is getting the input from opOne
into opThree
. My entire code is below. Apologies in advance for unused variables, I've yet to clean the code up to look pretty.
using namespace std;
class TravelLog {
private:
double _elapsedTime[1000] = { 0 };
double _speed[1000] = { 0 };
public:
//variables
const double speed = 30;
double speedInput[30] = { 0 };
const double time = 30;
double timeInput[30] = { 0 };
int inputSpeed;
int inputTime;
double miles;
int index = 1;
//functions
void menu();
int opOne(double speed, double time);
int opTwo(double miles);
int opThree(double speed, double time);
void opFour();
};
//Sets the template for me to use without modifying the actual template
TravelLog A;
//Function for option 1 to take in speed and time
//leave this alone for right now
int TravelLog::opOne(double speed, double time)
{
//Takes in speed input
cout << "Speed: ";
cin >> A.inputSpeed;
//for loop to take in the time input and store it into an array
//Takes in speed input
cout << "Time: ";
cin >> A.inputTime;
A.index++;
return 0;
}
//function for option 2 to take in ammount of miles
int TravelLog::opTwo(double miles)
{
return 0;
}
//funcion for option 3 to print the records
int TravelLog::opThree(double speed, double time)
{
//for loop to take in the speed input stored in the array and print it out
for (int i = 0; i < A.index; i++)
{
A.speedInput[i] = inputSpeed;
cout << "Speed: ";
cout << A.speedInput[i] << endl;
}
//for loop to take in the time input stored in the array and print it out
for (int i = 0; i < A.index; i++)
{
A.timeInput[i] = A.inputTime;
cout << "Time: ";
cout << A.timeInput[i] << endl;
}
cout << endl;
return 0;
}
//This function works: No Need to Edit
void TravelLog::opFour()
{
cout << "Exiting the program. TravelLog Deleted.";
}
//This function works: No need to Edit
void TravelLog::menu()
{
double input;
cout << "1. Input speed and total time elapsed." << endl;
cout << "2. Total miles" << endl;
cout << "3. Records." << endl;
cout << "4. Exit." << endl;
cout << "Your input: ";
cin >> input;
if (input == 1)
{
TravelLog a;
a.opOne(0, 0);
}
else if (input == 2)
{
TravelLog b;
b.opTwo(0);
}
else if (input == 3)
{
TravelLog c;
c.opThree(0, 0);
}
else if (input == 4)
{
TravelLog d;
d.opFour();
exit;
}
return;
}
int main()
{
cout << "Please select:" << endl;
// (^_^) Please write your codes here //
for (int b = 0; b < 1000; b++)
{
TravelLog e;
e.menu();
}
return 0;
}```