🔒 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
  • 768
    Views
  • 9
    Participants
Last reply from:
PHC-KILATIS12

Trending Topics

Online now

Members online
1,143
Guests online
1,192
Total visitors
2,335

Forum statistics

Threads
2,274,287
Posts
28,954,833
Members
1,234,178
Latest member
mackymackss00
Back
Top