# Small program using "if" and some variables assistance.

This is a discussion on Small program using "if" and some variables assistance. within the C++ Programming forums, part of the General Programming Boards category; Code: do { cout << "\n"; cout << "Input s, u, v, a and t: (0 for unknown)\n"; cin >> ...

1. Code:
```do {
cout << "\n";
cout << "Input s, u, v, a and t: (0 for unknown)\n";
cin >> s >> u >> v >> a >> t;
cout << "Which variable do you need?\n";
cin >> var;

if ( var=="v" && u!=0 && a!=0 && t!=0 )
{
float v=u + a*t;
cout <<"Final velocity = "<< v <<" m/s\n";
}
else if ( var=="v" && u!=0 && a!=0 && s!=0 )
{
float v=sqrt( u*u+2*a*s );
cout <<"Final velocity = "<< v <<" m/s\n";
}
else if ( var=="s" && u!=0 && t!=0 && a!=0 )
{
float s=u*t + 0.5*a*t*t;
cout << "Displacement = "<< s <<" m\n";
}
else if ( var=="s" && a==0 )
{
float s=0.5*(u + v)*t;
cout << "Displacement = "<< s <<" m\n";
}
else
{
cout << "Insufficient/Invalid Input!\n";
}

}while (1);```

2. Reserve an invalid value as "unknown," eg -1.

Page 3 of 3 First 123