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.