Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 01-13-2005, 12:31 AM   #1 (permalink)
Timber
Registered User
 
Join Date: Jan 2005
Posts: 9
Timber is on a distinguished road
problem with paycode

Hi guys, I am very new to C++ and programming for that matter. I am trying to learn step by step but i always seem to get stuck and examples in books don't seem to help.

Anyway I am having this problem for calculating pay. I need to get the paycode to be automatically assigned to the payrate when the user enters it. How am I to get around it and what am I doing wrong. Thanks
Code:
#include <iostream>
using namespace std;

int main (void)
{
	int i;
	int paycode[4]={0,1,2,3};
	float payrate[5]={10.00, 11.50, 14.00, 20.00};
	float hrs,pay;
	

	
	for (i=0;i<5;i++)

	cout<<"Enter hours worked:"<<endl;
	cin>> hrs;
	cout<<"Enter pay code:"<<endl;
	cin>> code[i];

		
	pay= hrs * code[i];

					
	{
		cout <<"Pay="<<pay<<endl;
	}

	return 0;
}

Last edited by Valmont; 01-13-2005 at 12:59 AM.
Timber is offline   Reply With Quote
Old 01-13-2005, 01:09 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Code:
#include <iostream>
#include <string>

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

//Optional function: depends on IDE. Prevents from "console flashing".
//1) Remove if not needed by IDE. 2) Remove for final release.
void wait_for_enter();

int main()
{
  double payrate[4]={10.00, 11.50, 14.00, 20.00};
  double hrs,pay;

  int payRateCode;
  for (int i = 0; i < 5; ++i)
  {
    cout<<"Enter hours worked:"<<endl;
    cin >> hrs;
    cout<<"Enter pay rate code: (0 = 10, 1 = 11.5, 2 = 14, 3 = 20)"<<endl;
    cin >> payRateCode;
    pay = hrs * payrate[payRateCode];
    cout << "Pay = " << pay << endl;
  }

  wait_for_enter();
  return 0;
}

//---------------------------------------------------

void wait_for_enter()
{
  cout << "press <enter> to continue...";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
__________________
Valmont is offline   Reply With Quote
Old 01-19-2005, 12:34 AM   #3 (permalink)
Timber
Registered User
 
Join Date: Jan 2005
Posts: 9
Timber is on a distinguished road
Thanks for the quick reply
Timber is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Assignment (Urgent help req.) Boltress Standard C, C++ 0 01-12-2005 07:59 AM
looping problem maria_arif MS Technologies ( ASP, VB, C#, .NET ) 1 11-29-2004 08:07 AM
omfg... well, i may need help just understanding this problem... .pakmon. Standard C, C++ 3 01-08-2004 08:44 AM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM


All times are GMT -8. The time now is 06:31 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting