My C++ program has a little error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

My C++ program has a little error

Can you please help me check what is the problem with my program. Can you also help me check what I did wrong? Thanks https://code.sololearn.com/cx2HnC2M9eZR/#cpp

15th Apr 2020, 2:59 AM
SmallNinja2006
SmallNinja2006 - avatar
30 Answers
+ 1
small ninja Look, a little longer but much easier
15th Apr 2020, 3:38 AM
Ahmed Erfan
Ahmed Erfan - avatar
+ 4
You can say that it is a like=up vote and dislike=down vote for a comment or a post or a question
15th Apr 2020, 5:03 AM
Ahmed Erfan
Ahmed Erfan - avatar
+ 2
You're welcome 😊
15th Apr 2020, 3:56 AM
Ahmed Erfan
Ahmed Erfan - avatar
+ 2
Oh, thanks man. You have been helping all the way... Thanks
15th Apr 2020, 5:28 AM
SmallNinja2006
SmallNinja2006 - avatar
+ 2
There are two mistakes in code: (1.)The 'switch' case statement only works with 'constant expressions' not 'conditional statements'. (2.)Missing ';' in line 24. Bonous advice:- LEARN TO READ THE ERROR MESSAGES ..as they tell all the errors precisely and also the line number in which it exists.....
15th Apr 2020, 5:15 PM
Aditya Narayan Chaurasia
Aditya Narayan Chaurasia - avatar
+ 2
Use if else much better
15th Apr 2020, 8:25 PM
Het Patel
Het Patel - avatar
+ 2
Use semicolon after break.only constant values are used in switch case.
16th Apr 2020, 7:58 PM
Layan Moyura
Layan Moyura - avatar
+ 1
You can't use expressions like x>0 or x<0 in switch..case sentence but you can use ranges like saying: int x=8; switch (x){ case 0 ... 10: cout<<x<<endl; break; //outputs 8. So that's the first error & the second one is that you forgot to put ' ; ' after every break. And to correct the program i advice you to use if & if else statements it will be easier to finish your program successfully. I hope i explained it well.
15th Apr 2020, 3:20 AM
Ahmed Erfan
Ahmed Erfan - avatar
+ 1
Thanks a lot...
15th Apr 2020, 3:55 AM
SmallNinja2006
SmallNinja2006 - avatar
+ 1
Can I ask a question? What is the voting for this? Other than that, it is possible to make a scientific calculator using C++ but it takes a lot of lines right?
15th Apr 2020, 4:01 AM
SmallNinja2006
SmallNinja2006 - avatar
+ 1
Yes you can make scientific calculator " scientific not basic" but it will need you to be an advanced c++ programmer but you can make a basic calculator that use +,-,/,* operators using if & if else statements it will be good if you make it, you can try 😃.
15th Apr 2020, 4:09 AM
Ahmed Erfan
Ahmed Erfan - avatar
+ 1
You can also made simple calculator using switch
15th Apr 2020, 4:11 AM
Vinayak Dutt
Vinayak Dutt - avatar
+ 1
oh Okok, I'll try... Actually previously, I tried making a basic calculator with the operators but I also tried with squaring a number. I tried programming it before, then I only came to try this website. It took a lot of line. But now I know switch, it will be easier...
15th Apr 2020, 4:23 AM
SmallNinja2006
SmallNinja2006 - avatar
+ 1
What is the voting thing at the top left corner of the screen for?
15th Apr 2020, 4:46 AM
SmallNinja2006
SmallNinja2006 - avatar
+ 1
Put ; in break statements and don't put case <=0: //Case × put case Interger<=0: //Case ✓
15th Apr 2020, 6:10 AM
Bibek
Bibek - avatar
+ 1
I am new student i want to learn programming languages What is the best language?
15th Apr 2020, 8:41 PM
said awsm
said awsm - avatar
+ 1
you can see here. this is my simple code . i hope it can help you. https://code.sololearn.com/cQ31ftHdCqlp/?ref=app
15th Apr 2020, 9:11 PM
Zeroo
Zeroo - avatar
+ 1
Use easily use if and else in place of switch statement #include <iostream> using namespace std; int main() { int integer; cout << "Input a number: " ; cin >> integer; cout<<integer<<endl; if(integer<0) { cout << "This is a negative number.\n"; cout << "Your number is: " << integer << endl; } else if(integer>0) { cout << "This is a positive number.\n"; cout << "Your number is: " << integer << endl; } else if(integer==0) { cout << "The number is a zero.\n"; } else { cout << "This is not even a number..." << endl; } return 0; }
16th Apr 2020, 9:14 AM
SAHIL VISHWAKARMA
SAHIL VISHWAKARMA - avatar
+ 1
Switch statements are only for constant inputs Like input is 7 So case 7: You cannot place any conditional statements in switch statements It is better to use if else statements in this type of program Hope to make a change....
16th Apr 2020, 12:27 PM
100 subs with 2 videos
100 subs with 2 videos - avatar
16th Apr 2020, 7:44 PM
Yashkumar Navadiya
Yashkumar Navadiya - avatar