// The distance between two towns is 380km. A car and a lorry started from the two towns at the same time. At what speed drove the two vehicles, if the speed of the car is with 5km\ faster than the speed of the lorry and we know that they met after 4 hours? Use Dynamic Memory Allocation and Pointer in calculating and Displaying the needed info.
// The distance between two towns is 380km. A car and a lorry started from the two towns at the same time. At what speed drove the two vehicles, if the speed of the car is with 5km\ faster than the speed of the lorry and we know that they met after 4 hours? Use Dynamic Memory Allocation and Pointer in calculating and Displaying the needed info.
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <string>
int main ()
{
int t=4;
int d=380;
int dt=20;
int dd;
int * ptr;
int * ptr2;
ptr = (int*) malloc (500*sizeof(int));
ptr2 = (int*) malloc (500*sizeof(int));
dd=d-dt;
ptr = dd/8;
ptr2 = ptr+5;
cout << " The Speed of the Car is: " << ptr << endl;
cout << " The Speed of the Lorry is: " << ptr2 << endl;
return(0);
}
How can i make this run? How to use dynamic memory allocation in all variables? Thanks.