Does anyone can fix this problem?

#include <cstdio>
#include <iostream>

using namespace std;

int main ()
{
int speed;
int hour;
int distance;
bool notValid;
int a=1;

do{
notValid=false;
cout << "\nWhat is the speed of the vehicle in mph? " ;
cin >> speed;
if (speed < 0)
{
cout << "\nYou have entered invalid data";
notValid=true;
}
} while (notValid);

do{
notValid=false;
cout << "\n How many hours has it traveled? " ;
cin >> hour;
if (hour < 1)
{
cout << "\nYou have entered invalid data";
notValid=true;
}
} while (notValid);

{
cout << "\n\nDay Distance";
cout << "\n-------------------\n";


for(a==1; a <= hour; )
{
distance= (speed*hour);
cout << a;
cout << " ";
cout << distance;
cout << " ";
cout <<"\n\n";
a++; }
system("pause");

return 0;
}
}


Any one can fix my program? I don't know why it show me the same value in the output
Will be gald to help if you could just use code tags for posting code and use soem indentation in your code.
Did you mean this:

distance= (speed*hour*a)

It is difficult to tell what you want, because you do not have any comments in the code, and your explanation of the problem is severely lacking. Note also that you have == instead of = in your for loop.
closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
    for(a = 1; a <= hour; ++a) 
    { 
        distance = speed * a; 
        cout << a;
        cout << " "; 
        cout << distance; 
        cout << " "; 
        cout <<"\n\n";  
    }
Additionally, you should use cin.get(); instead of that system("pause");
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.