What's wrong with code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What's wrong with code?

I'm trying to make its say 36.1 - 37.1 is OK but anything under or over isn't ok https://code.sololearn.com/cdX2913l75i2/?ref=app?

6th Oct 2020, 4:11 PM
Lugli
Lugli - avatar
32 Answers
+ 6
In your code i noticed two errors fist one u used cin>>a; and a Variable is defined after cin so its error Second one is you put semicolon in if condition remove it .see this code #include <iostream> using namespace std; int main() { int a; cin << a; float x = 36.9; float y = 36.1; if(a<y || a>=x) cout << "ok" << endl; cout << "Not ok" << endl; }
6th Oct 2020, 5:32 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 8
Lugli if first condition will be true then it wont check any other condition if first one will false then it will Check else if condition it this will also false then else part will execute u can use only if statement instead of else if and else statements.
7th Oct 2020, 2:24 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 7
https://code.sololearn.com/cdX2913l75i2/?ref=app This is the code Ipang I am not an expert of C++, so I can't help.
6th Oct 2020, 4:34 PM
Gabriele Gatti
Gabriele Gatti - avatar
+ 4
♨️♨️ I didn't understand about the first error you're talking about. What's wrong in that? Float a; means both definition and declaration so we have allocated a memory for the variable and cin>>a; will store a value in a.
8th Oct 2020, 6:18 AM
Sneh Chauhan
Sneh Chauhan - avatar
+ 2
Ananthu SV else is not compulsory u can use if instead of else statement.
7th Oct 2020, 6:08 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Azudi kenneth Chinedu In MS Windows programs can save data in the Windows Registry. They use system API calls to do that.
8th Oct 2020, 12:30 AM
Brian
Brian - avatar
+ 1
With 'a' declared as an int type, the value can never be within the accepted range. You should declare it as float.
6th Oct 2020, 9:48 PM
Brian
Brian - avatar
+ 1
You use if ladder means if all the condition true then every statement execute
7th Oct 2020, 4:26 AM
Niteesh
+ 1
If you need source code to adjust this then message me i will respond
7th Oct 2020, 4:27 AM
Niteesh
+ 1
♨️♨️ I think this must be the code he is looking for 😅 #include <iostream> using namespace std; int main() { float a; cin >> a; float x = 36.9; float y = 36.1; if(a>=y && a<=x) { cout << "OK" << endl ; }else{ cout << "Not ok" << endl; } }
7th Oct 2020, 6:19 AM
Ananthu SV
Ananthu SV - avatar
+ 1
Azudi kenneth Chinedu, this is off topic for the current question. I will be glad to help, but first post it as a new question so we can continue there.
8th Oct 2020, 12:35 AM
Brian
Brian - avatar
8th Oct 2020, 9:30 AM
Neha Jain
Neha Jain - avatar
0
Move the code link from the title into the Description. Links do not work in title or tags.
6th Oct 2020, 4:17 PM
Ipang
0
Gabriele Gatti I already checked the code, but I just want anyone visiting this thread to also be able to see it, and can respond 👌
6th Oct 2020, 4:37 PM
Ipang
0
♨️♨️ Thanks for helping. Just checked ur profile and ur like a coding God you know like 50 languages.
6th Oct 2020, 9:04 PM
Lugli
Lugli - avatar
0
Where is else keyword?
7th Oct 2020, 6:05 AM
Ananthu SV
Ananthu SV - avatar
0
Ananthu SV yeah that's what I was trying to do Thanks
7th Oct 2020, 6:21 AM
Lugli
Lugli - avatar
0
Lugli thats fine bro ✌️😊
7th Oct 2020, 6:22 AM
Ananthu SV
Ananthu SV - avatar
0
In 17 line use else if in place of if #include <iostream> using namespace std; int main() { float a; cin >> a; float x = 36.9; float y = 36.1; float z = 100; if(a>=y && a<=x) { cout << "OK" << endl ; } else if (a>z) { cout << "stop capping" << endl; } else{ cout << "Not ok" << endl; } }
7th Oct 2020, 12:56 PM
Abhishek God
Abhishek God - avatar
0
Abhishek god how does else if work?
7th Oct 2020, 2:21 PM
Lugli
Lugli - avatar