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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:36:12+00:00 2026-06-10T18:36:12+00:00

I am trying to test this simple function, but Opt.status, Opt.Year values are not

  • 0

I am trying to test this simple function, but Opt.status, Opt.Year values are not returned back to main(). Why? Please help as I am new to C++.I am using visual c++ to execute these codes.This is in my .cpp file

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "stdio.h"

using namespace std;


int main() 
{
    Easy_Task obj_EasyTask;
    TimeDateMonthOptions whatOptions=DATE;
    TOptions Opt;
    Opt.status=FALSE;
    Opt.Year=1970;

    printf("Enter code\n");
    scanf("%d",&obj_EasyTask.code);

    cout << "the code entered is: " << obj_EasyTask.code;
    obj_EasyTask.display2(obj_EasyTask.code);

    cout << "\nOutput: " << obj_EasyTask.show();

    printf("\nEnter the options that you prefer\n");
    scanf("%d",&whatOptions);


    obj_EasyTask.display3(whatOptions, Opt);

    cout << "\nOpt.Year: " << Opt.Year;

    if(Opt.status)
    {
        obj_EasyTask.x=(Opt.Year)& 0x00FF;
        obj_EasyTask.y=((Opt.Year)& 0xFF00)>>8;
        cout << "\nX: " << obj_EasyTask.x;
        cout << "\nY: " << obj_EasyTask.y;
        obj_EasyTask.Result=(obj_EasyTask.x)*(obj_EasyTask.y);
    }


    char holdWindow;
    std::cin >> holdWindow;
    return 0;
}


uint16_t Easy_Task::display2(uint16_t code) 
{
    if(code==1)
    {
        c = 7;
    }
    else
    {
        c = 9;
    }
    return c;

}

uint16_t Easy_Task::display3(TimeDateMonthOptions whtOptions, TOptions Opt)
{
    switch(whtOptions)
    { 
        case 0:
        case 1:
        case 2:
        case 3:
            Opt.status=TRUE;
            cout << "\nStatus1: " << Opt.status;
            Opt.Year=1991;
            cout << "\nYear1: " << Opt.Year;
        break;
        case 7: 
            Opt.status=FALSE;
            cout << "\nStatus2: " << Opt.status;
            Opt.Year=2013;
            cout << "\nYear2: " << Opt.Year;
        break;
        default:
            Opt.status=FALSE;
            cout << "\nStatus3: " << Opt.status;
            Opt.Year=2010;
            cout << "\nYear3: " << Opt.Year;
        break;

    }
    return Opt.status, Opt.Year;

}

In my .h file I have the class defined as follows:

#pragma once

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>

typedef unsigned short uint16_t;

#define TRUE 1;
#define FALSE 0;


typedef struct TOptions
{
    bool status;
    uint16_t Year;
};

typedef enum 
{
    YEAR,
    MONTH,
    DATE,
    HOURS,
    MINUTES,
    SECONDS,
    HUNDRETHS,
    UNDEFINED
}TimeDateMonthOptions;


class Easy_Task
{
public:

    uint16_t code, c, x,y, Result;
    uint16_t display2(uint16_t code);

    uint16_t show()
    {

        return c;
    };

    uint16_t display3(TimeDateMonthOptions whatOptions, TOptions Opt);

};     

The problem I have is line:
if(Opt.status)

Where it doesn’t return the value of 1 but instead in takes the default value which was defined earlier. Why is this happening?

  • 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-10T18:36:13+00:00Added an answer on June 10, 2026 at 6:36 pm

    Better still define a function to return TOptions
    TOptions Easy_Task::display3(...); and return a structure.
    Remember that you can only ever return ONE SINGLE return value from the function.

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

Sidebar

Related Questions

I'm trying to create a simple function to do a status test. Goal is
This is for Play! Framework 2.0. I'm trying to write a simple test case
just trying to test for equality in this piece of code, but getting a
I was trying to export a simple test function for a dll to work
Ihave simple test console application. I'm trying to use function nike2 from defined in
I'm trying to make a simple linear regression function but continue to encounter a
I'm trying to make a simple in in-page popup called like this: var test
I'm trying to test the first answer to this question: SQL - message schema
I'm trying to test for something's visibility with $(this).css('display')==none; The problem is, it works
Following on from this question...I'm trying to unit test the following scenario: I have

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.