Im really new to this C++ programming. I can do basic things a bit like Nested IF, some looping like For Loop,While Loop,Do..While Loop.. However, Im stuck with this Switch Case question. Im quite clueless on what to change in my coding.
I hope I can learn a lot about C++ programming here. Nice knowing you all people.
Here is the question : (https://imgur.com/a/V9eMbRT)
Here is my current answer. I could not produce the output like I wanted. It's confusing.
#include <iostream>
using namespace std;
int main (){
float Price;
int Age;
char Gender;
cout << " What is your gender?" << endl;
cin >> Gender;
cout << " How old are you?" << endl;
cin >> Age;
switch (Gender){
case 'M' :
cout << " You are a Male" <<endl;
break;
case 'F' :
cout << " You are a Female" <<endl;
break;
case 'C' :
cout << " You are a child" <<endl;
break;
}
switch (Age){
case 'M' :
Age > 50;
Price = 45.99;
cout << " You are " <<Age << " years old"<<endl;
cout << " Price is " << Price << endl;
Age <=50;
Price = 56.59;
cout << " You are " << Age << " years old"<<endl;
cout << " Price is " << Price << endl;
case 'F' :
Age > 45;
Price = 43.99;
cout << " You are " << Age << " years old"<<endl;
cout << " Price is " << Price << endl;
Age <= 45;
Price = 43.99;
cout << " You are " << Age << " years old"<<endl;
cout << " Price is " << Price << endl;
case 'C' :
Age >2;
Price = 12.99;
cout << " You are " << Age << " years old"<<endl;
cout << " Price is " << Price << endl;
Age <= 2;
Price = 5.99;
cout << " You are " << Age << " years old"<<endl;
cout << " Price is " << Price << endl;
break;
}
return 0;
Aucun commentaire:
Enregistrer un commentaire