About Char Arrays

This Is My Question.
1
2
3
4
5
Method    Rate 
a            56.66
t            43.66
c            32.33
u            54.22



The User Must Enter a,t,c,u Then It Will Display The Rates.My Question Is Can Char Arrays Hold Integer Values? Or Is There Any Other Method To Handle Two Data Types In A Single Array....I Hope I Will Get Some Help,I Don't Need Anyone To Do The Code. Thanks You.

EDIT:: My Qst Is ....Is There A Library In C++ To Handle Two Data Types In One Array? Correct Me Pl z If I'm Wrong. Thank You
Last edited on
You can use the std::pair to hold 2 data types in 1 array.

 
    std::pair<char, float> smth;

I think it's in the iostream library
I don't understand you completely.
If you mean (for example) for each char value, return an int value, you can use map<char,int>
1
2
3
4
5
6
7
8
9
10
11
12
#include <map>
#include <iostream>
using namespace std;
int main(){
// sth ...
map<char,int> mp;
mp['a']=56.66;
mp['t']=43.66;

cout>>mp['a']>>" ">>mp['t'];
return 0;
}


The output will looks like:
 
56.66 43.66
Last edited on
A char is an int since it it can hold a value from 0 - 255. Each of these possible values represents a character on an ASCII table. Because of this a char is an int, just with a more limited range. For example the statement:
char x = 97
is perfectly valid and x will then store the character 'a' However, if you need to use an int, you should use an int right? I don't see any need to do this. In this case you should either use a map as hackinghorn pointed out, or if you don't like the STL just create a second array where the elements match up (i.e. method[0] = 'a' and rate[0] = 56.66)
Last edited on
Topic archived. No new replies allowed.