0

Help me to complete this

#include <iostream> using namespace std; int main() { int choice=0; int length=0, breadth=0; cout << "welcome to Abdulrahman's calculator\n" cout<< "enter a shape from the option below\n" cout<<"1. Rectangle" cout<<"2. square"; cin>>choice; if (choice==1) cout<<"you have slected Rectangle\n"; cout<<"enter the value for length\n"; cin>>length; cout<<"enter the value for bradth\n"; cin>>breadth; int area = length * breadth; cout<<" area of the rectangle is"<<area }

4th Jul 2021, 10:29 AM
Abdul Rahman Suleman
Abdul Rahman Suleman  - avatar
3 Answers
0
Mention your problem with the code. It will not generate errors as it is syntactically correct but logically may wrong . Your if block has no braces {} so it has only 1 line . So if input is not 1,then also it will ask breath and length inputs... What is your expected output and inputs ..? edit: what is that link ? how it is related? Abdul Rahman Suleman at last after 'area' put semicolon.
4th Jul 2021, 10:37 AM
Jayakrishna 🇼🇳
0
#include <iostream> using namespace std; int main() { int choice=0; int length=0, breadth=0; int side,area,area_square; cout << "welcome to Abdulrahman's calculator\n"; cout<< "enter a shape from the option below\n"; cout<<"1. Rectangle"; cout<<"2. square"; cin>>choice; switch(choice) { case 1: cout<<"you have slected Rectangle\n"; cout<<"enter the value for length\n"; cin>>length; cout<<"enter the value for bradth\n"; cin>>breadth; area = length * breadth; cout<<" area of the rectangle is"<<area; break; case 2: cout<<"you have selected Square\n"; cout<<"Enter the side of square="; cin>>side; area_square=side*side; cout<<"area of square="<<area_square; break; default: cout<<"wrong choice"; } return 0; } https://code.sololearn.com/cA5a8a8a215A
4th Jul 2021, 10:59 AM
Abhishek Kumar
Abhishek Kumar - avatar
- 1
https://sololearn.com/discuss/2826895/?ref=app
4th Jul 2021, 10:29 AM
Abdul Rahman Suleman
Abdul Rahman Suleman  - avatar