Does anyone can fix this problem?

Feb 9, 2011 at 5:06am
#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
Feb 9, 2011 at 5:52am
Will be gald to help if you could just use code tags for posting code and use soem indentation in your code.
Feb 9, 2011 at 6:11am
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.
Feb 9, 2011 at 9:40am
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";  
    }
Feb 9, 2011 at 10:21am
Additionally, you should use cin.get(); instead of that system("pause");
http://www.cplusplus.com/forum/beginner/1988/
Topic archived. No new replies allowed.