+ 3
Whats the problem in this piece of code that I had written ?Its not working as I want it to be. Its just a small portion.plz hlp
#include <iostream> using namespace std; //greekmythfan //PLEASE ENTER YOUR GENDER FIRST //PLEASE ENTER A NUMBER BETWEEN 0 AND 100 int main() { int num; string gender; string rel ; cin>>gender; if(gender=="male"){rel="son";} else{if(gender=="female"){rel="daughter";} else{cout<<"YOU DONT KNOW YOUR GENDER BRUH";} } cin>>num; cout<<"Your number is "<<num<<"\n"; if(num<=8){cout<<"You are the"<<rel<<" of Hades \n" "GOD OF UNDERWORLD \n" "It's true because your godly instincts told you to choose that number ";}
6 Réponses
+ 16
The only error is the bracket at the end. Just add a '}'. In the input box you have to seperate your input with the enter key:
gender
num
Thats all
I hope this helps you
+ 4
No No ... plz ignore the small mistakes (if there are ) like semicolon etc. ( as I said it's only a piece of a bigger code ) Plz tell me why it's not working (if you understood what I want from the the code ) and what changes can be made.
thnx for the answers...
+ 2
error:
1. line no.13 remove the brace between else and if
2. line no.16 remove the brace
3. last line add a brace
+ 1
error: expected '{'
hint: there are 2 mistakes with brackets
+ 1
Well... actually the "small mistakes" aren't small if they prevent the code from compiling. With the brackets fixed the code is working.
Maybe you could add something in the last if condition to just output the text when gender is actually male or female
to add more statements you can use logic operators
if (x == 0 && y > 0){
// && -> and
}
But first you need to fix the "small mistakes"
+ 1
The last bracket isn't the only mistake...
Error messages depending brackets need to be taken with a grain of salt. It's more a hint that there is something wrong with brackets. The line number doesn't really point to a direct location in such a scenario.