C++ Program to convert a positive number into a negative number and negative number into a positive number using switch statements.
Flowchart to convert a +ve number into a -ve number
C++ Program to convert a positive number into a negative number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include<iostream> #include<conio.h> using namespace std; int main() { float number; int choice; cout<<"Select 1, for Negative to positive"<<endl; cout<<"Select 2, for positive to negative"<<endl; cin>>choice; switch(choice) { case 1: cout<<"Enter a Negative number"<<endl; cin>>number; number=number*(-1); cout<<"the Positive form of the number is"<<endl; cout<<number; break; case 2: cout<<"Enter a Positive number"<<endl; cin>>number; number=number*(-1); cout<<"Negative form of the number is"<<endl; cout<<number; break; default: cout<<"Invalid Input, or Characters entered"<<endl; } } |
Output
Select 1, for Negative to positive
Select 2, for positive to negative
1
Enter a Negative number
-6
the positive form of the number is
6
SFT (Shamil’s Flow Table )
Are you interested to Read about SFT(Shamil’s Flow Table)?