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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:04:29+00:00 2026-06-11T18:04:29+00:00

So the variable hoursWorked is not initialized. But how am I supposed to initialize

  • 0

So the variable hoursWorked is not initialized. But how am I supposed to initialize it if I want it to equal whatever the user stores in it? For example I want hoursWorked to be whatever any person outputs in it in cin. Here is my code:

#include <iostream>

using namespace std;

int main () 
{
   //Declare Variables
   double hoursWorked;
   double payRate;
   double incomeBeforeTax;

   payRate = 15;
   incomeBeforeTax = payRate * hoursWorked;

   cout << "Enter hours worked: ";
   cin >> hoursWorked;
   cout << endl;
   cout << incomeBeforeTax << endl; 

   return 0;
}
  • 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-11T18:04:30+00:00Added an answer on June 11, 2026 at 6:04 pm

    The calculation of incomeBeforeTax which references hoursWorked needs to occur after you initialize it by reading from cin. Move that line after cin >> hoursWorked; and it will work:

    payRate = 15.0;
    
    cout << "Enter hours worked: ";
    cin >> hoursWorked;
    
    incomeBeforeTax = payRate * hoursWorked;
    
    cout << endl;
    cout << incomeBeforeTax << endl;
    

    C++, like most procedural languages evaluates your code in the order in which it is written. That is, incomeBeforeTax = payRate * hoursWorked; assigns a value to incomeBeforeTax based on the current values of payRate and hoursWorked. These must be defined and initialized before the assignment is performed. That is what cin >> hoursWorked does.

    On a side note, double variables are best initialized with double literals so add .0 to the value.

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

Sidebar

Related Questions

The variable strCSSClass often has a value but sometimes is empty. I do not
JSTL variable values are not shown in EL. For example this code: <%@ taglib
The variable $page includes a webpage (full HTML file), but I want to filter
Variable names in haskell need to be in small case, but How to declare
the variable doc is not accessible anywhere else in the method outside of the
I have a js variable with many functions, and I want to create in
I have bitmap image variable and i want to bind it to my xaml
Consider variable like var url='http://www.example.com/index.php?id=ss'; or var url='http://www.example.com/dir1/dir2/index.php'; In these variables, i want to
VARIABLE: ... UNARYOP: 'not' Expression; // unary operation BINARYOP: 'or' VARIABLE; Expression : (NIL
Now I have read and on this but i am just stuck. Any help

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.