c - How to read an array and analyse the input -


i wondering there way read array , based upon letters entered something?

like example: if roman numeral; mm entered there way see 2 m's entered , display value m?

output be: 1000+1000.

could tell me name of function, because assignment dont want doing me, dont know start from.

example: char romannumerals[2] = {"mmmcmxcviii"};

char romannumerals[2] = {"mmmcmxcviii"}; 

is not right can hold 1 element(+1 \0). change to

char romannumerals[] = "mmmcmxcviii"; 

the compiler choose correct size array when doing above initialization.

then,you need variable add sum of each roman number. create

int sum=0; 

and need loop length of array times want check each letter.

int i,len=strlen(romannumerals); for(i = 0;i < len;i++) { //body of loop } 

string.h should included in order use strlen function returns length of string.

now,check each letter inside body of for loop using

if(romannumerals[i]=='m')     sum=sum+1000; else if(romannumerals[i]=='c')     sum=sum+/*the corresponding value*/; else if(...)     sum=sum+/*value*/; //etc etc 

and @ last,print sum.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -