I am new to C++,this problems seems to be basic. I am using char in the indices of array, everything seems to be correct, I don't understand why I am not able to fetch the value from the array, please help me!. even after typecasting char is not converting to int. The code runs fine if I use menu[n-'0'].
#include<iostream>
using namespace std;
int main(){
char n;
int price,q;
float menu[]={10,20,30};
float sum=0;
cin>>n;
while(n!='n' and n!='N'){
price=menu[(int)(n)];
cout<<price<<endl;
cin>>n;
}
cout<<sum;
return 0;
}