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}
// chap5proj.cpp : Defines the entry point for the console application.
//
# include <stdafx.h>
# include <iostream>
usingnamespace 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;