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
30 Answers
+ 1
small ninja
Look, a little longer but much easier
+ 4
You can say that it is a like=up vote and dislike=down vote for a comment or a post or a question
+ 2
You're welcome 😊
+ 2
Oh, thanks man. You have been helping all the way... Thanks
+ 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.....
+ 2
Use if else much better
+ 2
Use semicolon after break.only constant values are used in switch case.
+ 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.
+ 1
Thanks a lot...
+ 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?
+ 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 😃.
+ 1
You can also made simple calculator using switch
+ 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...
+ 1
What is the voting thing at the top left corner of the screen for?
+ 1
Put ; in break statements and don't put case <=0:
//Case ×
put case Interger<=0:
//Case ✓
+ 1
I am new student i want to learn programming languages
What is the best language?
+ 1
you can see here. this is my simple code . i hope it can help you.
https://code.sololearn.com/cQ31ftHdCqlp/?ref=app
+ 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;
}
+ 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....
+ 1
https://code.sololearn.com/cf3rZlWFPGVE/?ref=app
Your solution