Welcome to Dream.In.Code
Click Here
Getting C++ Help is Easy!

Join 117,541 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,659 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



structure for time

 
Reply to this topicStart new topic

structure for time

akb13
post 20 Jul, 2008 - 12:38 AM
Post #1


New D.I.C Head

*
Joined: 19 Jul, 2008
Posts: 3

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
User is offlineProfile CardPM

Go to the top of the page


KYA
post 20 Jul, 2008 - 09:02 AM
Post #2


#include <nerd.h>

Group Icon
Joined: 14 Sep, 2007
Posts: 3,087



Thanked 24 times

Dream Kudos: 1150
My Contributions


You are using selection = 1 instead of the assignment operator for comparison which is ==

Also, you didn't access your struct anywhere in that program. Which is fine since you can do this logically without one, but it is a requirement for your assignment.
User is offlineProfile CardPM

Go to the top of the page

akb13
post 21 Jul, 2008 - 08:21 PM
Post #3


New D.I.C Head

*
Joined: 19 Jul, 2008
Posts: 3

It's cool now. I got it figured out. Thanks.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 10/7/08 05:19PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month