LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2016, 12:59 PM   #1
codex96
LQ Newbie
 
Registered: Feb 2016
Posts: 5

Rep: Reputation: Disabled
Help Debugging some logical errors in program NEWBIE


My code is below im having some trouble debugging s




#include<iostream>
#include<string>
using namespace std;
class Worker
{
private:
int idNum;
string lastName;
string firstName;
double salary;
public:
void displayWorker();
void setIdNum(int);
void setLastName(string);
void setFirstName(string);
void setSalary(double);


};

void Worker::setIdNum(int id)
{
const int LOWID = 0;
const int HIGHID = 999;
if(id < LOWID || id > HIGHID)
id = LOWID;
else
id = id;
}
void Worker::setLastName(string last)
{
lastName = last;
}
void Worker::setFirstName(string first)
{
firstName = first;
}
void Worker::setSalary(double payRate)
{
const double LOWPAY = 5.75;
const double HIGHPAY = 99.99;
if (salary < LOWPAY || salary > HIGHPAY)
payRate = LOWPAY;
else
payRate = payRate;
}

void Worker::displayWorker()
{
cout << "ID #" << idNum << " Name: " << firstName << " " << lastName
<< " Salary: $" << salary << endl;
}


int main()
{
Worker aWorker;
aWorker.setIdNum(333);
aWorker.setLastName("Vasquez");
aWorker.setFirstName("Juan");
aWorker.setSalary(15.65);
aWorker.displayWorker();
return 0;
}
 
Old 02-15-2016, 06:02 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Use code tags, what are you trying to debug, what errors are you getting?
 
1 members found this post helpful.
Old 02-15-2016, 09:10 PM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
as above please use code tags

PHP Code:

[code
place 
the 
code 
here
[/code
also HOW are you building the c++ code?
your build line please
also what OS and what is it's version

also WHAT errors are you getting ?
 
Old 02-16-2016, 08:06 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Looks like Windows. What exact problems are you encountering?
 
Old 02-16-2016, 08:36 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,678

Rep: Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892Reputation: 5892
Welcome to LinuxQuestions.

It looks like a valid c++ program. At first glance you have a few problems in your conditional statements for id and salary functions.
 
Old 02-16-2016, 01:24 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
At this juncture I'd also like to point out the following link Welcome to LQ
 
Old 02-16-2016, 06:13 PM   #7
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Quote:
Originally Posted by codex96 View Post
My code is below im having some trouble debugging s

Code:
void Worker::setSalary(double payRate)
{
   const double LOWPAY = 5.75;
   const double HIGHPAY = 99.99;
   if (salary < LOWPAY || salary > HIGHPAY)
     payRate = LOWPAY;
   else
     payRate = payRate;
 }
I think you transposed "salary" and "payRate" in that bit of code.

Last edited by psionl0; 02-16-2016 at 06:14 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ newbie i really need some help debugging a program chilla101 Programming 2 10-29-2015 12:11 PM
[SOLVED] Debugging Kerberos authentication errors for NFSv4 with shark bucovaina78 Linux - Networking 1 12-05-2014 06:46 AM
C program - RTLD - Help with Debugging nikunjbadjatya Programming 1 03-23-2011 10:22 PM
java script and debugging errors in Slack justwantin Slackware 2 02-22-2009 08:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration