Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,547 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,567 people online right now. Registration is fast and FREE... Join Now!




Compiler Error

 
Reply to this topicStart new topic

Compiler Error, undeclared identifier error

Student44
24 Nov, 2007 - 03:24 PM
Post #1

New D.I.C Head
*

Joined: 24 Nov, 2007
Posts: 3


My Contributions
I am getting the following 3 errors:

error C2065: 'hours_worked' : undeclared identifier
error C2065: 'pay_rate' : undeclared identifier
error C2065: 'wages' : undeclared identifier

*****************************************************/
CODE

/* File: Mod2_exercise                                 */
/*                                                   */
/* Created by: Beverly Hill                          */
/* Date: November 23, 2007                           */
/*                                                   */
/* Program to compute the weekly wages               */
/*                                                   */
/* Inputs: (keyboard)                                */
/* 1. No. of hours worked during a week (integer)    */
/* 2. Pay rate (dollars per week) (float)            */
/*                                                   */
/* Output:                                           */
/* weekly wages displayed on screen as a float       */
/*                                                   */
/* Algorithm: wages = hours worked * pay rate        */
/*                                                   */
/****************************************************/

#include <iostream>

using namespace std;

int main()

{

40;//No. of hrs worked during week
13.50; //Pay rate: dollars per week
540.00;//Weekly wages

// read in the hours worked

cout << endl;
cout << "Number of hours worked during"
     << " the week (integer) = ";
cin >> hours_worked;

// read in the pay rate

cout << "Weekly pay rate (specify two digits "
     << "after the decimal point) = ";
cin << pay_rate;

// compute wages

// Program to compute the weekly wages;

// display the result

cout << endl;
cout << "The weekly wages are: $" << wages << endl;

return (0); // terminate with success

}


This post has been edited by William_Wilson: 24 Nov, 2007 - 03:40 PM
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Compiler Error
24 Nov, 2007 - 03:43 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
code.gif
all of your cin lines assign values to variables, but you do not create the variables anywhere.

at the top of your program you need to put something like:
CODE

int pay_rate,hours_worked,wages;

or doubles, or floats, depending on what you want to accept as values
User is offlineProfile CardPM
+Quote Post

Student44
RE: Compiler Error
24 Nov, 2007 - 04:08 PM
Post #3

New D.I.C Head
*

Joined: 24 Nov, 2007
Posts: 3


My Contributions
QUOTE(William_Wilson @ 24 Nov, 2007 - 04:43 PM) *

code.gif
all of your cin lines assign values to variables, but you do not create the variables anywhere.

at the top of your program you need to put something like:
CODE

int pay_rate,hours_worked,wages;

or doubles, or floats, depending on what you want to accept as values


When you say "top of your program" I'm not sure where that means specifically. we were asked to copy this code from a class exercise and just add info at the header section. I didn't change anything except that and the numeric values entered.
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Compiler Error
24 Nov, 2007 - 05:46 PM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,868



Thanked: 53 times
Dream Kudos: 550
My Contributions
I am sorry to take frustrations out on you, but this is the second post in a row that I have answered that perplexes me: Do you not have a book on C or C++. Have you ever used ANY programming language before?

QUOTE
CODE
40;//No. of hrs worked during week
13.50; //Pay rate: dollars per week
540.00;//Weekly wages


How in the world did you end up with these lines? How did that make sense to you? Have you ever written a program (and I don't mean copy) before?

...based upon those lines I don't even know how to help except to start at the very beginning...

Do classes not come with books anymore?

Ok, frustration aside:

You need to place these values into variables. So for example if I want a program that counts to 10:
CODE
#include <iostream>

using namespace std;

int main() {
    int i; // i is a integer variable, it holds numeric values
    //the for-loop will execute the code inside the brackets as long as i < 10
    //  at the end of each iteration it will increase i by 1 (i++).
    for (i=1; i<=10; i++) {
        cout << i; //print out the number held in i
        cout << endl; // move to the next line
    }
    return 0;
}


A variable holds a number so that you can use it later. So for example a simple multiplication program:
CODE
#include <iostream>

using namespace std;

int main() {
    //Variables must be declared before they are used
    int firstNumber, secondNumber, result;
    //prompt the user:
    cout << "Enter your first number: ";
    //get a number from the user
    cin >> firstNumber;
    //prompt the user
    cout << "Enter your second number: ";
    //get a number form the user
    cin >> secondNumber;
    //calculate the product, and place value into 'result'
    result = firstNumber * secondNumber;
    //print out the result...
    cout << endl;
    cout << "The Product is: ";
    cout << firstNumber;
    cout << " * ";
    cout << secondNumber;
    cout << " = ";
    cout << result;
    cout << endl;
    return 0;
}


Note that you must declare variables before you use them. To declare a variable you must tell the compiler its data type, its name, and optionally an initial value.

data_type identifier [= initial_value];

CODE
int anInteger;
double aFloatingPointReal = 3.14159;
int you, can, declare, more, than, one, this, way;



I highly recommend you read over some basic tutorials and get a feeling for the language. Don't just copy examples... try to edit the code and make it do more. Try to understand the grammar.
User is offlineProfile CardPM
+Quote Post

Student44
RE: Compiler Error
25 Nov, 2007 - 03:17 AM
Post #5

New D.I.C Head
*

Joined: 24 Nov, 2007
Posts: 3


My Contributions
QUOTE(NickDMax @ 24 Nov, 2007 - 06:46 PM) *

I am sorry to take frustrations out on you, but this is the second post in a row that I have answered that perplexes me: Do you not have a book on C or C++. Have you ever used ANY programming language before?

QUOTE
CODE
40;//No. of hrs worked during week
13.50; //Pay rate: dollars per week
540.00;//Weekly wages


How in the world did you end up with these lines? How did that make sense to you? Have you ever written a program (and I don't mean copy) before?

...based upon those lines I don't even know how to help except to start at the very beginning...

Do classes not come with books anymore?

Ok, frustration aside:

You need to place these values into variables. So for example if I want a program that counts to 10:
CODE
#include <iostream>

using namespace std;

int main() {
    int i; // i is a integer variable, it holds numeric values
    //the for-loop will execute the code inside the brackets as long as i < 10
    //  at the end of each iteration it will increase i by 1 (i++).
    for (i=1; i<=10; i++) {
        cout << i; //print out the number held in i
        cout << endl; // move to the next line
    }
    return 0;
}


A variable holds a number so that you can use it later. So for example a simple multiplication program:
CODE
#include <iostream>

using namespace std;

int main() {
    //Variables must be declared before they are used
    int firstNumber, secondNumber, result;
    //prompt the user:
    cout << "Enter your first number: ";
    //get a number from the user
    cin >> firstNumber;
    //prompt the user
    cout << "Enter your second number: ";
    //get a number form the user
    cin >> secondNumber;
    //calculate the product, and place value into 'result'
    result = firstNumber * secondNumber;
    //print out the result...
    cout << endl;
    cout << "The Product is: ";
    cout << firstNumber;
    cout << " * ";
    cout << secondNumber;
    cout << " = ";
    cout << result;
    cout << endl;
    return 0;
}


Note that you must declare variables before you use them. To declare a variable you must tell the compiler its data type, its name, and optionally an initial value.

data_type identifier [= initial_value];

CODE
int anInteger;
double aFloatingPointReal = 3.14159;
int you, can, declare, more, than, one, this, way;



I highly recommend you read over some basic tutorials and get a feeling for the language. Don't just copy examples... try to edit the code and make it do more. Try to understand the grammar.



Thanks for your assistance. I don't have a C+ Book. This is my fourth week with the class. It's supposed to be introductory programming.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 09:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month