Answer to Question #174645 in C++ for Pradeepraj

Question #174645

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”.


1
Expert's answer
2021-03-23T03:40:12-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS