i dont know why i am not getting what exactly i want? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

i dont know why i am not getting what exactly i want?

#include <string> #include <iostream> #include<cstdlib> using namespace std; int main() { int a,i=0,j=0,k=0,l=0; string you[4]={"motivational","good","fool","excellent"}; for (int x = 1; x <= 10; x++) { a=rand()%4; cout << you[a] << endl; cout<<a<<endl; if(a=0){ i+=1; } else if(a=1){ j+=1; } else if(a=2){ k+=1; } else{ l+=1; } } cout<<i<<endl; cout<<j<<endl; cout<<k<<endl; cout<<l<<endl; } output:- good 1 excellent 3 fool 2 motivational 0 good 1 motivational 0 fool 2 fool 2 fool 2 motivational 0 0 10 0 0

25th Dec 2018, 7:13 AM
Aamir Mehmood
2 Answers
+ 1
I'm not sure what kind of output you want. But if(a=1) etc should be if(a==1) Because = is assigment operator, not compasiron
25th Dec 2018, 7:37 AM
Taste
Taste - avatar
0
yup ... no dobt.....the mistake i made was use of assignment operator(=) instead of equal(==)....
25th Dec 2018, 10:44 AM
Aamir Mehmood