I am having trouble understanding structure in C++. I need to create a console app that converts minutes to either hour/minutes or seconds. One of the program requirements is a structure for time. I looked in my book, my lecture, attended the live lecture, searched the net and I'm still stumped. The program compiles fine but will only show 0 hours and 0 minutes. Here is my code.
CODE
/* Specification
Lab 2 Exercise 3
This program uses constants, enumeration for menu options, structure type for time, and a decision statement to format time as user specifies */
# include <iostream>
using namespace std;
int main()
{
enum menu {hourMin = 1, seconds = 2};
//structure time
struct Time
{
int Hr;
int Min;
int Sec;
};
//declaring variables
int minInput = 0;
int selection = 0;
//declaring constants
const int convertHr = minInput / 60;
const int convertMin = minInput % 60;
const int convertSec = minInput * 60;
//user inputs minutes
cout << "Enter a whole number of minutes to convert: ";
cin >> minInput;
cout << endl;
//display menu
cout << "Choose a converstion type\n";
cout << hourMin << " - Hour/minute format\n";
cout << seconds << " - Seconds\n";
cout << "Enter your selection: ";
cin >> selection;
//find selection using decision statement and show output
if (selection = 1 )
{
cout << "Result: " << minInput << " minutes equals " << convertHr << " hours and "
<< convertMin << " minutes" << endl;
}
else
{
cout << "Result: " << minInput << " minutes equals " << convertSec << " seconds"
<< endl;
}//end if
cout << endl;
return 0;
}//end main
This post has been edited by akb13: 20 Jul, 2008 - 12:39 AM