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

  • Home
  • SEARCH
  • 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 1093663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:51:28+00:00 2026-05-16T23:51:28+00:00

I am attempting a simple time display program in C++. Edited #include <iostream> #include

  • 0

I am attempting a simple time display program in C++.


Edited

#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;

class vClock
{
    public:

        // constructor
        vClock(int = 0, int = 0);

        // mutable member functions
        void set_time(int, int);
        void time_ahead(int);

        // constant function
        string time_notation(int) const;
        void show_time() const;

    private:
         int hour;
         int minute;
         int offset_hour;
         int offset_minute;
         int maxhour;
         int maxminute;
         int carrier;
};

// member function implementation 

vClock::vClock(int hr, int min)
{
    hour = hr;
    minute = min;
    maxhour = 24;
    maxminute = 60;
    carrier = 0;
}

void vClock::set_time(int hr, int min)
{
    hour = hr;
    minute = min;
}

void vClock::time_ahead(int add_minute)
{
            // suppose to be a short cut for all cases

        carrier = ((add_minute + minute) / maxminute);
        offset_hour = hour + carrier;
        offset_minute = (add_minute + minute) - (carrier * maxminute);

        cout << "After " << add_minute << "minutes, the time will be "
             << setfill('0') << setw(2) << offset_hour << ":" << setw(2) << offset_minute << time_notation(offset_hour)<< endl;

    return;
}

string vClock::time_notation(int hr) const
{
    if(hour < 12)
        cout << "AM";
    if (hour >= 12)
        cout << "PM";
}

void vClock::show_time() const{

    cout << setfill('0') 
          << setw(2) << hour << ':'
          << setw(2) << minute 
          << time_notation(hour) << endl;
    return;

}

// member functions implementation END


int main()
{
    vClock sample;

    sample.set_time(0,59);
//  sample.show_time();

    sample.time_ahead(118);

    return EXIT_SUCCESS;
}

It seems like time_notation is being evaluated before the cout statement?

*AM*After 118minutes, the time will be 02:57


solved

I cannot compile it anymore – my IDE will crash, after I added the time_notation(offset_hour) to time_ahead() and show_time() (located in the last line of the two function bodies).

Before implementing that function and use it in other functions, the compiling was all right. The program worked fine.

Is it illegal?

I received a very long error message

clock-time.cpp:65: error: no match for ‘operator<<‘ in ‘(+std::operator<< [with _CharT = char, _Traits = std::char_traits](((std::basic_ostream >&)(+std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(+(+std::operator<< [with _CharT = char, _Traits = std::char_traits](((std::basic_ostream >&)(+std::operator<< [with _CharT = char, _Traits = std::char_traits](((std::basic_ostream >&)(+std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(+(+std::operator<< [with _Traits = std::char_traits](((std::basic_ostream >&)(&std::cout)), ((const char*)”After “)))->std::basic_ostream<_CharT, _Traits>::operator<< with _CharT = char, _Traits = std::char_traits)), ((const char*)”minutes, the time will be “)))), std::setfill with _CharT = char))), std::setw(2)))->std::basic_ostream<_CharT, _Traits>::operator<< vClock%3a%3aoffset_hour”>with _CharT = char, _Traits = std::char_traits)), ((const char*)”:”)))), std::setw(2)))->std::basic_ostream<_CharT, _Traits>::operator<< vClock%3a%3aoffset_minute”>with _CharT = char, _Traits = std::char_traits << ((vClock*)this)->vClock::time_notation(((vClock*)this)->vClock::offset_hour)’

I am using MinGW C++ compiler, and my IDE is jGRASP.
Any help is appreciated.

Thank you!

  • 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-16T23:51:29+00:00Added an answer on May 16, 2026 at 11:51 pm

    That’s because time_notation returns void. A void cannot be printed as it is an incomplete type.

    Not sure though why IDE should crash.

    Fix probably is to change time_notation to return 'string' type.

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

Sidebar

Related Questions

I'm attempting to make a simple linear text game that will display inside a
I'm attempting to run a very simple Blackberry/Java application which implements the BrowserField class.
I'm attempting to do a simple bubble sort code to get familiar with list/string
I'm attempting to set up a simple Mac-based 2D tiling engine, using a 2D
I'm attempting to compile a simple hello world program in c with lcc-win32/wedit, and
I am attempting to create a simple java form using Swing. The idea basic
I'm writing a simple time tracking program to manage my own projects. I'm a
I'm attempting to pass a string to my start method via a simple web
I'm attempting to make a simple game of Pairs for Android. Program Structure Menu.java
I'm attempting to do something extremely simple - take the current date and time,

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.