Greetings everyone,
I am thankful for any help that you may give me. I am working on a program that takes a trips start time and end time, then shaves 25% off the time it takes to complete the trip. However, while doing a static cast, I get the error of 'non-lvalue in assignment'. Everything else seems to work, at least from what I can tell. There are no other errors or warnings during an attempt to compile.
Here is my source code:
------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int starttime = 0;
cout << "\nPlease enter the start time for the old trip in 24 hour format (hhmm): ";
cin >> starttime;
cin.get();
int endtime = 0;
cout << "\nPlease enter the end time for the old trip in 24 hour format (hhmm) :";
cin >> endtime;
cin.get();
// Declare integers c and pt for static casting later.
int newtime = 0;
int pt = 0;
//Get hours and minutes from the start time
float hours = endtime / 100 - starttime / 100;
float mins = endtime % 100 - starttime % 100;
float starthours = starttime/100;
float startmins = starttime%100;
// Take Minutes, divide by sixty to get hours(from minutes)
float minToHours = mins/60.0;
// Same as above, but with the starting minutes
float startMin = startmins/60.0;
// Get the total hours (from minutes to hours, and regular hours)
float added = minToHours + hours;
// Same as above, but with starting minutes and hours
float added1 = startMin + starthours;
float newhours = added - (added / 4);
float pretime = added1 + newhours;
static_cast<int>(pt) = added1 + newhours;
float fmins = pretime - pt;
// Declare final numbers for the newtime calculation
float newHours = pt * 100;
float newMinutes = fmins * 60;
static_cast<int>(newtime) = newHours + newMinutes;
cout.fill ('0');
cout << "Your new ending time is: " << setw(4) << newtime << endl;
system("PAUSE");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------
These are the two static casts I am having problems with:
static_cast<int>(pt) = added1 + newhours;
static_cast<int>(newtime) = newHours + newMinutes;
Again, thank you for the help!
I am thankful for any help that you may give me. I am working on a program that takes a trips start time and end time, then shaves 25% off the time it takes to complete the trip. However, while doing a static cast, I get the error of 'non-lvalue in assignment'. Everything else seems to work, at least from what I can tell. There are no other errors or warnings during an attempt to compile.
Here is my source code:
------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int starttime = 0;
cout << "\nPlease enter the start time for the old trip in 24 hour format (hhmm): ";
cin >> starttime;
cin.get();
int endtime = 0;
cout << "\nPlease enter the end time for the old trip in 24 hour format (hhmm) :";
cin >> endtime;
cin.get();
// Declare integers c and pt for static casting later.
int newtime = 0;
int pt = 0;
//Get hours and minutes from the start time
float hours = endtime / 100 - starttime / 100;
float mins = endtime % 100 - starttime % 100;
float starthours = starttime/100;
float startmins = starttime%100;
// Take Minutes, divide by sixty to get hours(from minutes)
float minToHours = mins/60.0;
// Same as above, but with the starting minutes
float startMin = startmins/60.0;
// Get the total hours (from minutes to hours, and regular hours)
float added = minToHours + hours;
// Same as above, but with starting minutes and hours
float added1 = startMin + starthours;
float newhours = added - (added / 4);
float pretime = added1 + newhours;
static_cast<int>(pt) = added1 + newhours;
float fmins = pretime - pt;
// Declare final numbers for the newtime calculation
float newHours = pt * 100;
float newMinutes = fmins * 60;
static_cast<int>(newtime) = newHours + newMinutes;
cout.fill ('0');
cout << "Your new ending time is: " << setw(4) << newtime << endl;
system("PAUSE");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------------------------
These are the two static casts I am having problems with:
static_cast<int>(pt) = added1 + newhours;
static_cast<int>(newtime) = newHours + newMinutes;
Again, thank you for the help!