Implement a C++ program to perform addition and multiplication on two numbers, where the first number has to declare in namespace named as “window” and the second number has to declare in namespace named as “wind”.
#include <iostream>
namespace window{
float first_number;
}
namespace wind{
float second_number;
}
int main(){
int choice;
std::cout<<"Input first number: ";
std::cin>>window::first_number;
std::cout<<"Input second number: ";
std::cin>>wind::second_number;
std::cout<<"Do you want to 1. Add or 2. Multiply? (1 or 2): ";
std::cin>>choice;
if(choice == 1)
std::cout<<window::first_number<<" + "<<wind::second_number<<" = "<<window::first_number + wind::second_number<<std::endl;
else if(choice == 2)
std::cout<<window::first_number<<" x "<<wind::second_number<<" = "<<window::first_number * wind::second_number<<std::endl;
else std::cout<<"Invalid choice.";
return 0;
}
Comments
Leave a comment