compiler error "left operand must be l-value"

I am having problems compiling this program. line 29 causes the error "left operand must be l-value". Please help me to fix this.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
1 // chap5proj.cpp : Defines the entry point for the console application.
2//
3# include <stdafx.h>
4# include <iostream>
5using namespace std;
6
7int main()
8{
9double mph, time, disPerHour, milesTrav;
10
11cout << "This program will evaluate the distance a car has traveled" << endl;
12cout << "for each successive hour up to the maximum specified travel time." << 13endl << endl;
14cout << "Please enter the speed of the car in miles per hour: ";
15cin >> mph;
16cout << "\nThank you. Now enter the maximum time the car traveled rounded to 17the " << endl;
18cout << "nearest hour: ";
19cin >> time;
20while (mph < 0 || time < 1)
21{ cout << "You have input invalid entries into the program." << endl;
22cout << "Please be sure the miles per hour is not a negative number" <<endl;
23cout << " and time traveled is at least a value of 1." << endl;
24break;
25}
26cout << "Hour Distance Traveled\n";
27cout << "-----------------------\n";
28disPerHour = 1;
29mph * disPerHour = milesTrav;
30for (; disPerHour <= time; disPerHour++)
31cout << disPerHour << "\t\t" << milesTrav;
32system ("PAUSE");
33return 0;
34}
Here's the exact same code with a modicum of whitespace sanity.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// chap5proj.cpp : Defines the entry point for the console application.
//
# include <stdafx.h>
# include <iostream>
using namespace std;

int main()
{
    double mph, time, disPerHour, milesTrav;

    cout << "This program will evaluate the distance a car has traveled" << endl;
    cout << "for each successive hour up to the maximum specified travel time." << 13endl << endl;
    cout << "Please enter the speed of the car in miles per hour: ";
    cin >> mph;

    cout << "\nThank you. Now enter the maximum time the car traveled rounded to 17the " << endl;
    cout << "nearest hour: ";
    cin >> time;

    while (mph < 0 || time < 1)
    { 
        cout << "You have input invalid entries into the program." << endl;
        cout << "Please be sure the miles per hour is not a negative number" <<endl;
        cout << " and time traveled is at least a value of 1." << endl;
        break;
    }

    cout << "Hour Distance Traveled\n";
    cout << "-----------------------\n";

    disPerHour = 1;
    mph * disPerHour = milesTrav; //compiler says NOPE!

    for (; disPerHour <= time; disPerHour++)
        cout << disPerHour << "\t\t" << milesTrav;
    system ("PAUSE");
    return 0;
}

The offending line is backward. You can't do that operation on the left side of an assignment.
milesTrav = mph * disPerHour;
Last edited on
thank you very much. Also, I apologize for the lack of whitespace (noob error.)
Topic archived. No new replies allowed.