Can someone run my code template to see what's wrong?

#include "stdafx.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[ ])

int a = 40;		            //No. of hrs worked during week
float b = 12.75;       		//Pay rate: dollars per hour
float c = 510;              //Weekly wages
cout << a * b;
cout << c;

// read in the hours worked

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

// read in the pay rate

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

// compute wages

float weekly_wages;

// display the result

cout << endl;
float 510 << wages << endl;

return (0); // terminate with success

9 Years
Discussion Span
Last Post by stilllearning

First wrap your code in code tags .

Now this line float 510 << wages << endl; makes no sense whatsoever. You do realize that "<<" needs to be prepened by an object of the class ostream, not a variable of type float or a constant. If you want to display the wages it should be something like cout << "The wages are " << wages << endl; And your code is not reading any input values in anywhere !! how do you expect it to compute the wages ? And you've defined your variable as "weekly_wages" yet you are trying to output a variable called "wages" which is not even declared anywhere.

Here are some basics

#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main(){
  int hours;

  // ask the user for an input
  cout << "How many hours have you worked? " << endl; 
  // read the number of hours worked
  cin >> hours;  
  // display the value read 
  cout << " You have worked " << hours << " hours" << endl; 

  return 0;
I know this is simple, but this is my first time. I'm having a tough time understanding. Can someone walk me though the code? Please

Well then start with something basic. Here is a tutorial that explains how "cin" and "cout" can be used for I/O.

Here is another tutorial. I would suggest reading the C++ Basics part, which should cover most of what you are attempting to do.

And code tags are only for your code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.