GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Sep-2008, 22:06
L_i_o_n L_i_o_n is offline
New Member
 
Join Date: Sep 2008
Posts: 4
L_i_o_n has a little shameless behaviour in the past

Error C2106: '=' : left operand must be l-value


The Program says: A long-distance carrier charges the following rates for telephone calls:

00:00-6:59 .12 per min
07:00-19:00 .55 per min
19:01-23:59 .35 per min

Write a program that asks for the starting time and the number of minutes of call, and displays the charges. The program should ask for the time to be entered as a floating point number in the form HH.MM. For example, 07:00 hours will be entered as 07.00, and 16:28 will be entered as 16:28.

Input validation: The program should not accept times that are greater than 23:59. Also, no number whose last two digits are greater than 59 should be accepted. Hint: Assuming num is a floating-point variable, the following expression will give you its fractional part:
num - static_cast<int>(num)

Here is my code Its half completed because I like to check and see if my logic works but if you have any alternative and much easier forms of code I would appreciate it very much Its due tommorow and it looks like im up tonight figureing this one out. I need help on this error that i get all the time.

c:\users\sign on\documents\visual studio 2008\projects\long distance calls\long distance calls\long_ distance_ calls.cpp(36) : error C2106: '=' : left operand must be l-value

Code:

CPP / C++ / C Code:
#include <iostream>
using namespace std;

int main()
{
	float number;
	float time;
	double rateOne=.12;
	double rateTwo=.55;
	double rateThree=.35;
	float charges;


	cout << "This program determines the total cost of your bill." << endl;
	cout << "Please enter the number of hours you talked your input should be between" << endl;
	cout << "0 and 23.59. Also the miniutes must be less than 60," << endl;
	cin >> time;

	if (time > 23.59)
	{
	cout << "Please enter a time between 0 and 23.59 where the whole numbers are hours." << endl;
	}
	if (time-static_cast<int>(time)>.59)
	{
		cout << "Please enter a valid amount of miniutes." <<endl;
	}
	else if (time > 19.01)
	{
	number = 23.59 - time;
	charges = rateOne*60*6*59 + rateTwo*13*60 + rateThree* number=static_cast<int>(number)*60 + rateThree*(number-static_cast<int>(number))/100;
	charges= static_cast<double>(charges);
	cout << charges << endl;
	}
	else if (time > 7.00)
	{
	charges= rateOne*60*6*59+rateTwo*(time=static_cast<int>(time))*60*time-static_cast<int>(time);
	cout << charges << endl;
	}
	


	
	


		system("Pause");

		return 0;
}
Last edited by LuciWiz : 23-Sep-2008 at 03:24. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 22-Sep-2008, 22:08
L_i_o_n L_i_o_n is offline
New Member
 
Join Date: Sep 2008
Posts: 4
L_i_o_n has a little shameless behaviour in the past

Re: Help I keep getting this error


Forgot to mention the error occurs at charges when it is first used in the if statement mixed with rate 1 etc.
  #3  
Old 22-Sep-2008, 22:39
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Help I keep getting this error


Quote:
Originally Posted by L_i_o_n
c:\users\sign on\documents\visual studio 2008\projects\long distance calls\long distance calls\long_ distance_ calls.cpp(36) : error C2106: '=' : left operand must be l-value
Line 36 of your code:
CPP / C++ / C Code:
charges=rateOne*60*6*59+rateTwo*(time=static_cast<int>(time))*60*time-static_cast<int>(time);
...has two incorrect assignments (look for two equal signs, '='...).

In the future, please wrap your code with code tags ([cpp] before, & [/cpp] afterwards...) to both format your code & make it simpler for others you are hoping will spend their time reviewing.
  #4  
Old 22-Sep-2008, 23:01
L_i_o_n L_i_o_n is offline
New Member
 
Join Date: Sep 2008
Posts: 4
L_i_o_n has a little shameless behaviour in the past

Re: Help I keep getting this error


Thanks man I appreciate you helping me with the error but I got fustrated and solved it a different way feel free to review the code now for the next program I hope your on just in case I need help

CPP / C++ / C Code:
#include <iostream>
using namespace std;

int main()
{
	float number;			//Defines Number Of Hours Between A Certain Interval of Hours
	float time;
	double rateOne=.12;
	double rateTwo=.55;
	double rateThree=.35;
	double charges;
	int wholeNumber;		//Defines Number as a whole Number
	float fractionNumber;	//Defines Number as a fraction


	cout << "This program determines the total cost of your bill." << endl;
	cout << "Please enter the number of hours you talked your input should be between" << endl;
	cout << "0 and 23.59. Also the miniutes must be less than 60," << endl;
	cin >> time;

	if (time > 23.59)
	{
	cout << "Please enter a time between 0 and 23.59 where the whole numbers are hours." << endl;
	}
	if (time-static_cast<int>(time)> .6)
	{
		cout << "Please enter a valid amount of miniutes." <<endl;
	}
	else if (time > 19.01 && time < 23.59)
	{
	number = time-19.01;
	fractionNumber= number-static_cast<int>(number);
	wholeNumber= number=static_cast<int>(number);	
	charges= (rateOne*60*6+ rateOne*59)+(rateTwo*13*60)+(rateThree* fractionNumber*100) + rateThree * wholeNumber * 60;
	charges=static_cast<double>(charges);
	cout << "Your Fee is $" << charges << endl;
	}
	else if (time > 7.00 && time < 19.01)
	{
	number = time - 7;
	fractionNumber = number-static_cast<int>(number);
	wholeNumber = number=static_cast<int>(number);
	charges= (rateOne*60*6)+(rateOne*59) + (rateTwo * wholeNumber * 60) + (fractionNumber * rateTwo*100);
	cout << "Your Fee is $" << charges << endl;
	}
	else if (time >=0 && time <7.00)
	{
	number = time;
	fractionNumber = number-static_cast<int>(number);
	wholeNumber = number=static_cast<int>(number);
	charges = (rateOne * 60 * wholeNumber) + (rateOne * fractionNumber*100);
	cout << "Your Fee is $" << charges << endl;
	
	}
	


	
	


		system("Pause");

		return 0;
}
  #5  
Old 22-Sep-2008, 23:30
ocicat ocicat is offline
Regular Member
 
Join Date: May 2008
Posts: 580
ocicat is a jewel in the roughocicat is a jewel in the rough

Re: Help I keep getting this error


Quote:
Originally Posted by L_i_o_n
I hope your on just in case I need help
Recognize that this site is not a live site meaning that your questions can and/or will be answered in real-time. In general, there are enough people answering questions here such that you will likely receive some form of answer within 0.5 - 1 day.

The best thing you can do both for yourself & for future discussion is be very clear as to the problem you are experiencing, & posting minimal code which generates the error seen. You would be surprised at how many people expect us to be mind readers.

Good luck.
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
Linked Lists advice request promsan C Programming Language 74 23-May-2007 09:29
Major newbie problem cynack MS Visual C++ / MFC Forum 1 08-Apr-2007 12:25
Winsock error when compiling FLTK 2.0 Projects mauriciorossi FLTK Forum 3 16-Aug-2005 11:18
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:47.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.