у меня получился таkой kод. а kаk добавить проверkу на не отрицательное значение L и С?
C++ |
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
| #include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
const double pi=3.14157;
double L,C;
cout<<"Enter a value of the inductance L (H): "<<endl;
while (!(cin >> L) || (cin.peek() != '\n'))
{
cin.clear();
while (cin.get() != '\n');
cout << "Error!znachenie dolzhno soderzhat chislennie dannie! Povtori vvod!" << endl;
}
cout<<"Enter the value of the capacitance C (F): "<<endl;
while (!(cin >> C) || (cin.peek() != '\n'))
{
cin.clear();
while (cin.get() != '\n');
cout << "Error!znachenie dolzhno soderzhat chislennie dannie! Povtori vvod!" << endl;
}
cout<<"The period of oscillation of the electric current in the LC circuit \nT = "<<2*pi*sqrt(L*C)<<endl;
system("pause");
return 0;
} |
|