You: Guess an integer number, but don’t tell me. Your friend: Okay! You: Now multiply it by 3. Your …
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
#include<stdio.h>
int main()
{
int n;
scanf(“%d”,&n);
int a[n],i;
long long int m;
char p[n];
for(i=0;i<n;i++){
scanf(“%s%d”,&p[i],&a[i]);
}
scanf(“%lld”,&m);
for(i=n;i>=0;i–){
if(p[i]==‘a’)m-=a[i];
else if(p[i]==‘s’)m+=a[i];
else if(p[i]==‘m’)m/=a[i];
else if(p[i]==‘d’)m*=a[i];
}
printf(“%lld”,m);
return 0;
}
char p[n]; // p is declared as a string here.
for (i = 0; i < n; i++){
scanf("%s%d",&p[i],&a[i]);
^^^ but why are you taking inputs as characters here?
}
It is not a Compilation error but an error in your codes logic. Though I have already pointed out the error already, try to find out what is wrong yourself.