Answer the question
In order to leave comments, you need to log in
Correct C++ code?
Task:
C++ Calculate the average speed of a motorcyclist in the section from point A to B through point B, if the distance between points A and B is S1, and between B and C - S2. The time of movement between A and B is t1, and between B and C is t 2. The average speed is defined as: V = (S1 + S2) / (t1 + t2). Parameters S1,S2,t1,t2 are entered by the user from the keyboard
Solution:
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "Russian");
int s1,s2,t1,t2;
float U;
cout<<"Введите скорость от А до Б s1 = ";
cin>>s1;
cout<<"Введите скорость от Б до В s2 = ";
cin>>s2;
cout<<"Введите время от А до Б t1 = ";
cin>>t1;
cout<<"Введите время от Б до В s2 = ";
cin>>t2;
if ((t1 > 0) || (t2 > 0))
{
U = (s1 + s2)/(t1 + t2);
cout<<"Средняя скорость U = " << U;
}
getchar();
return 0;
}
Answer the question
In order to leave comments, you need to log in
If the answer is correct for all input data, then the code is correct.
And also - use the markup when writing on the toaster - otherwise the inclusions were eaten
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question