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 8540903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:42:15+00:00 2026-06-11T11:42:15+00:00

I am creating a basic C++ code for my first school assignment that simply

  • 0

I am creating a basic C++ code for my first school assignment that simply requires me to create a program that asks for a time in hours, minutes and seconds and converts how much time this is equivalent to in seconds; extremely basic.

I think the errors I am getting are because of my possible misuse of the struct function.

After getting the same error: “expected primary-expression before â.â token” after multiple trials of tweaks, I decided to try the code without struct; simply defining them with float h,m,s,et and calling them by that name: cin >> h >> m >> s;. And it works. This is why I think the error is with my use of the struct function.

Here is the short code:

#include <iostream>

using namespace std;

int main() {

struct time {
 int hour;
 int minute;
 int second;
 int elapsedTime;
};

cout << "Enter a Time in the Format: HH MM SS: ";

cin >> time.hour >> time.minute >> time.second;

time.elapsedTime = ((time.hour*360)+(time.minute*60)+time.second);

cout << "The Amount of Time Elasped is: " << time.elapsedTime << " seconds." << endl;

return 0;

}

The aforementioned error is in the code’s 16th line 3 times and once in it’s 20th line.

Another error in the 18th line is: “expected unqualified-id before â.â token”.

Any help would be greatly appreciated. I refuse to look at the professor’s posted answers yet.

Thank you for your time 🙂

  • 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-06-11T11:42:16+00:00Added an answer on June 11, 2026 at 11:42 am

    With:

    struct time {
     int hour;
     int minute;
     int second;
     int elapsedTime;
    };
    

    you just declared the structure of your struct. You have to instantiate an instance of it:

    time mytime;
    cin >> mytime.hour;
    cin >> mytime.minute;
    cin >> mytime.second;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a fairly basic login form using PDO for the first time.
I am creating a project that uses EF Code First approach and now I
Using jQuery I'm creating a basic 'tooltip' animation so that the tooltip will appear
The basic setup is classic - you're creating a Windows Forms application that connects
I've got some (I think) pretty basic code for creating cell content from a
I am working on my first ever android app, and I'm creating basic exercise/calorie
I'm creating a Brainfuck parser (in a BASIC dialect) ultimately to create an interpreter
I am creating a simple mp3 player and my first task was to create
I'm trying to create a basic registration form that takes in an address with
I'm writing a basic program that copies a string from an existing text file

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.