distance traveled

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
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	int speed;
	int hours; 
	double totalmiles;
	int a = 1;

	cout << "This program allows the user to the speed and distance of a vehicle the display the total distance the vehicle went.\n\n";

	cout << "Enter the speed of vehicle in MPH: ";
	cin >> speed;
	cout << "Enter the hours it traveled: ";
	cin >> hours;

	cout << "\n\n";
	cout << "Hour, Speed, and Distance traveled" << endl;

	while (a != hours)
	{
		totalmiles = speed * a;
		cout << a << "  " <<  speed << "  " << totalmiles << endl;
		a = a + 1;
	}
	_getch();

	return 0;
}


I am missing something here, it works but it is buggy, like the enter speed of 40 and hours of 30, its suppose to print
1 40 40
2 40 80
3 40 120

but its buggy and i am only getting the first 2 hour and not the 3rd, any idea where the code is buggy at.
nevernmind i found the bug.

while (a != hours)

is suppose to be

while (a <= hours)
interesting coding List...
Topic archived. No new replies allowed.