Created
October 1, 2022 11:20
-
-
Save gcs-abdulwahab/cd249f603c9e46160011eb9bc1d39675 to your computer and use it in GitHub Desktop.
ITU_Assignment 0 for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a Program of a calculator.It will enter two numbers and a character from user and perform the entered operation. | |
#include <iostream> | |
using namespace std; | |
//This Function will output message on screen. | |
void OutputMessage() | |
{ | |
cout<<"Welcome to Faltu Calculator by Zuraiz, Israr and Munir...!!!"<<endl<<endl | |
<<"Enter number 65535 to END program"<<endl<<endl; | |
} | |
//It will enter "Number" from user and return that value. | |
int InputNumber() | |
{ | |
int input; | |
cout<<"Enter Number: "; | |
cin>>input; | |
return input; | |
} | |
//This function will prompt the user that which operation he would like to perform? | |
char InputOperation() | |
{ | |
//It should return a character | |
char operation=0; | |
while(1) // If User enters any character other then ( /, *, -, +, %) it should ask again. | |
{ | |
cout<<"Enter Operation ( /, *, -, +, %): "; | |
cin>>operation; | |
if(operation=='/') | |
{ | |
operation = '/'; | |
break; | |
} | |
if(operation=='+') | |
{ | |
break; | |
} | |
if(operation=='-') | |
{ | |
break; | |
} | |
if(operation=='*') | |
{ | |
break; | |
} | |
if(operation=='%') | |
{ | |
break; | |
} | |
else | |
cout<<endl<<"Invalid Input... \nEnter Again Chawal kaheen ke...!!!"<<endl; | |
} | |
return operation; | |
} | |
//It will calculate the answer As it will take all inputs and perform the operation on the both integer inputs | |
float Calculation(int first_input, int second_input, char operation) | |
{ | |
float answer=0; | |
switch (operation) | |
{ | |
case '/': | |
{ | |
answer= (float) first_input/second_input; | |
break; | |
} | |
case '*': | |
{ | |
answer=first_input*second_input; | |
break; | |
} | |
case '+': | |
{ | |
answer=first_input+second_input; | |
break; | |
} | |
case '%': | |
{ | |
answer=first_input % second_input; | |
break; | |
} | |
case '-': | |
{ answer=first_input-second_input; | |
break; | |
} | |
} | |
return answer; | |
} | |
//It will output answer on the screen. | |
void OutputAnswer(float answer) | |
{ | |
cout<<endl<<"ANSWER: "<<answer<<endl<<endl; | |
} | |
int main() | |
{ | |
int first_input; //first_input will have the first value and also the result | |
int second_input; | |
char operation; | |
OutputMessage(); | |
first_input= InputNumber(); | |
operation= InputOperation(); | |
second_input = InputNumber(); | |
while(second_input!=65536) | |
{ | |
float result=Calculation(first_input,second_input,operation); | |
OutputAnswer(result); | |
first_input = result; | |
operation= InputOperation(); | |
second_input = InputNumber(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment