0
Fever (int, double, float)
Write a program that takes body temperature in Celsius as input. If it is in range from 36.1 to 36.9 (not inclusive) print "OK", otherwise print “Not OK”. Sample Input 37.2 Sample Output Not OK https://code.sololearn.com/c4aSAa8A6ViN/?ref=app // What am I missing here??
13 odpowiedzi
+ 6
There are lots of problems with your c++ code.
Here is a corrected version:
#include <iostream>
using namespace std;
int main() {
//your code goes here
float temp;
cin >> temp;
if (temp >=36.1 && temp <36.9)
{
cout << "OK" << endl;
}
else {
cout << "Not OK";
}
return 0;
}
Here is the original version with the fixes commented:
#include <iostream>
using namespace std;
int main() {
float temp;
cin >> temp;
if (float temp >=36.1 && <=36.9); // remove the "float" and temp must be added for comparison with 36.9.
// remove the semicolons after the if-statement's condition
{
cout << "OK" << endl;
else "Not OK"; // you need to cout the "Not OK" string.
// You also need to end the if-statement's block before starting the else block.
}
return 0;
}
+ 3
Tahiti🍷
1 - How else inside if block
2 - why there is Semicolon after if condition
3 - why there is not cout in else part
4 - why there is float temp in if part
You need to think about above points.
if (float temp >=36.1 && <=36.9);
{
cout << "OK" << endl;
else "Not OK";
}
If program says print "Not ok" it means you have to use cout to print value.
so it would be cout << "Not ok";
+ 2
#include <iostream>
using namespace std;
int main() {
//your code goes here
float temp;
cin >> temp;
if (temp >=36.1 && temp <36.9)
{
cout << "OK" << endl;
}
else {
cout << "Not OK";
}
return 0;
}
Good Luck
+ 1
Josh Greig , I can’t believe I didn’t notice all those errors. Thanks for your assistance. I’ll try this again!
+ 1
I Am AJ ! - Thank you for those pointers. I’m surely learning a lot from all these errors.
+ 1
//NOT OK relpace--->Not OK
#include <iostream>
using namespace std;
int main() {
//your code goes here
float celsius;
cin>>celsius;
if(celsius>=36.1 && celsius<=36.9)
cout<<"OK";
else
cout<<"Not OK";
}
+ 1
#include <iostream>
using namespace std;
int main() {
//your code goes here
double temperature;
cin>>temperature;
if(temperature>=36.0 && temperature<=36.9)
{
cout<<"OK"<<endl;
}
else{
cout<<"Not OK"<<endl;
}
}
0
Tahiti🍷 why should you be followed huh? Show your skills then ask about followers !!
0
//Try this my long version.
#include <iostream>
using namespace std;
int main() {
double celciusDeg[9] = {36.1, 36.2, 36.3, 36.4, 36.5, 36.6, 36.7, 36.8, 36.9};
double userDeg;
cin>>userDeg;
if(userDeg == celciusDeg[0]){
cout<<"OK";
}
if(userDeg == celciusDeg[1]){
cout<<"OK";
}
if(userDeg == celciusDeg[2]){
cout<<"OK";
}
if(userDeg == celciusDeg[3]){
cout<<"OK";
}
if(userDeg == celciusDeg[4]){
cout<<"OK";
}
if(userDeg == celciusDeg[5]){
cout<<"OK";
}
if(userDeg == celciusDeg[6]){
cout<<"OK";
}
if(userDeg == celciusDeg[7]){
cout<<"OK";
}
if(userDeg == celciusDeg[8]){
cout<<"OK";
}
if(userDeg>=37.0)
{
cout<<"Not OK";
}
if(userDeg<=36.0){
cout<<"Not OK";
}
return 0;
}
0
Joseph, if the input was 36.15, the requirements say to print "OK" but your code will print nothing.
Comparing for equality with float or double also needs to be done with floating point error in mind. Some numbers that look clean and simple in base 10 end up impossible to perfectly represent as floating-points so the == operator returns false unexpectedly.
0
I hope you understand my code!
#include <iostream>
using namespace std;
int main()
{
float x; // x= temperature in celsius.
cin >> x;
if (x>36.1 && x<36.9)
{cout << "Ok" << endl;}
else
{cout << "Not Ok" << endl;}
}
0
#include <iostream>
using namespace std;
int main() {
//your code goes here
float temp;
cin >> temp;
if (temp >=36.1 && temp <36.9)
{
cout << "OK" << endl;
}
else {
cout << "Not OK";
}
return 0;
}
- 2
Tahiti🍷 bro follow me. I am a beginner