Jump to content

I am new to C++ programming. Please help with the following code

- - - - -

  • Please log in to reply
3 replies to this topic

#1
scabbo8304

scabbo8304

    Newbie

  • Members
  • Pip
  • 4 posts
#include "stdafx.h"

#include "iostream"

using namespace std;


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

{

float gross_pay, payrate;

int hours_worked;


//Input hours_worked 

cin>>hours_worked;


//Input pay rate

cin>>payrate;


//Regular pay calculation module

if	hours_worked<= 40;

	 

else	gross_pay = payrate * hours_worked;

Why won't this work. I am getting
error C2181: illegal else without matching if

Edited by ZekeDragon, 02 March 2011 - 03:18 PM.
Please use [CODE] tags (the # button) when posting code.


#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
If (hours_worked<= 40)
//Type here what will happend if its true

else
//type here what will happend if its false...


Also please tell me what you want the program to do... Would be easier for me too help that way...

#3
scabbo8304

scabbo8304

    Newbie

  • Members
  • Pip
  • 4 posts
TheCompBoy, thanks for replying.. Here's the full code.. I was still working on it.. I am trying to code calculation for gross pay.

/* Calculate gross pay */

/* declare functions */


#include "stdafx.h"

#include "iostream"

using namespace std;


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

{

float gross_pay, payrate, over_time, overtime_rate, reg_pay, over_time_pay;


int hours_worked;


//Input hours_worked 

cin>> hours_worked;


//Input pay rate

cin >> payrate;


//Regular pay calculation module

if	(hours_worked < = 40);

	reg_pay = payrate * hours_worked;

cout<< reg_pay;

else 


hours_worked > 40;


//Calulate over time

over_time= hours_worked - 40;


//gross pay calculation

over_time_pay = over_time * overtime_rate;


gross_pay = over_time_pay + reg_pay;

cout << gross_pay;





	return 0;

}

Edited by ZekeDragon, 02 March 2011 - 03:18 PM.
Please use [CODE] tags (the # button) when posting code.


#4
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
It should be <iostream>, not "iostream". Library name inside < > means compiler will look for it in it's include directory while " " means it will look where your program is saved.


if	(hours_worked < = 40)[B];[/B]

reg_pay = payrate * hours_worked;

cout<< reg_pay;

else 


hours_worked > 40;

No semicolon there, should be curly brackets since you have more than 1 statement following if statement. I guess else is probably missing if as well.
else if (hours_worked > 40)

A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users