Program Code Screenshot:
Sample Output:
'a' or 'b'? a
b
Program Code to Copy
#include <iostream>
using namespace std;
int main()
{
//Prompt for a or b
cout<<"'a' or 'b'? ";
char ch;
//Read the user choice
cin>>ch;
//If input is 'a', print 'b'
if(ch=='a'){
cout<<'b'<<endl;
}
//If input is 'b' , print 'a'
if(ch=='b'){
cout<<'a'<<endl;
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.