Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7428377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:44:11+00:00 2026-05-29T08:44:11+00:00

I have just started reading a C++ textbook and I am having trouble solving

  • 0

I have just started reading a C++ textbook and I am having trouble solving one of the coding problems at the end of the chapter. Here is the question:

Write a program that asks the user to enter an hour value and a minute value. The
main() function should then pass these two values to a type void function that displays
the two values in the format shown in the following sample run:

Enter the number of hours: 9
Enter the number of minutes: 28
Time: 9:28

my code so far is:

#include <iostream>
using namespace std;
void time(int h, int m);

int main()
{
    int hour, min;

    cout << "enter the number of hours: ";
    cin >> hour;
    cout << "enter the number of minutes: ";
    cin >> min;

    string temp = time(hour, min);

    cout << temp;

    return 0;
}

void time(int h, int m)
{
    string clock;
    clock =
}

What do I do now inside the time(n, m) function?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:44:11+00:00Added an answer on May 29, 2026 at 8:44 am

    You can include <iomanip> and set field width and fill so that times like 9:01 are printed properly. And since the function time should just print the time, building and returning a std::string can be omitted. Just print these values:

    void time(int hour, int min)
    {
        using namespace std;
        cout << "Time: " << hour << ':' << setfill('0') << setw (2) << min << endl;
    }
    

    Also note that writing using namespace std; at the beginning of your files is considered bad practice since it causes some of user-defined names (of types, functions, etc.) to become ambiguous. If you want to avoid exhausting prefixing with std::, use using namespace std; within small scopes so that other functions and other files are not affected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started reading up on Lucene. In one of the examples provided,
I've just started reading C and have a question about a macro. How can
I have just started learning ruby reading from different resources. One of them is
I just started reading this book Eloquent Ruby and I have reached the chapter
I've only just really started android developing and have been reading about services here
I knw its pretty basic question but I have just started reading it... I
I have just started reading about neural networks and I have a basic question.
I have just started reading through The C Programming Language and I am having
I have just started learning C# and would have one question that I cannot
I have just started reading Modern C++ Design Generic programming and Design Patterns Applied

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.