🔒 Closed C++ switch case using char type

Status
Not open for further replies.
anong sample code boss sa switch case gamit ang character type sa c++, ayaw kasi guman saakin, wala kasi akong makita sa google kakailang search nko laging interger gamit nila may char pero ayaw gumana
1610615584464.webp
 
okay lang if else..kaso char at integer yan ehh...hahahah kailangan char at integer din input nong iba..😅😂

or integer nalang kaya input mo...hahaha suggestion lang papss..☺️😊
 
kaya kung char isa lang pero may 1A sa switch. tsaka if icompare mo yung char sa integer may gagawin ka pa dun. baka you mean case '2': instead of case 2
 
pa try nito ts,
[CODE lang="cpp" title="Test" highlight="6,7,8,9,10"]#include <iostream>
#include <map>
using namespace std;
int main(void)
{
map<string, int> choice_map;
choice_map.insert({"1A", 1});
choice_map.insert({"2", 2});
choice_map.insert({"3", 3});
choice_map.insert({"4", 4});
string choice = "1A";
switch(choice_map[choice]) {
case 1:
cout<<"1\n";
break;
case 2:
cout<<"2\n";
break;
case 3:
cout<<"3\n";
break;
case 4:
cout<<"4\n";
break;
}
}[/CODE]
 
[XX='Botude, c: 676545, m: 1014161'][/XX] hindi po kami nag focus sa cpp paps, pero gumamit kami isang sem, 2 sem kami nag java.
 
ts kung yan ang form ng code mo, wag ka gumamit ng char datatype ang gamitin mo is string datatype mag include ka ng preprocessor para sa string
 
Status
Not open for further replies.

About this Thread

  • 20
    Replies
  • 790
    Views
  • 9
    Participants
Last reply from:
PHC-KILATIS12

Trending Topics

Online now

Members online
770
Guests online
1,979
Total visitors
2,749

Forum statistics

Threads
2,294,152
Posts
29,089,107
Members
1,208,107
Latest member
Dumplings999
Back
Top