0
How to solve code coach "balconies" using cpp
8 Respostas
+ 6
Abbas Maatouk show us what you have attempted so far please. WE are not here to GIVE you the solution but to help you with your attempt.
+ 3
code coach are for practicing and for checking you problem solving skill so try it yourself
+ 3
Abbas Maatouk The strings you believe are commas not strings.
thus getchar()
h , w
12,10.2
15.3,9.4
+ 2
Abbas Maatouk the task is
You are trying to determine which of two apartments has a larger balcony. Both balconies are rectangles, and you have the length and width, but you need the area.
Task
Evaluate the area of two different balconies and determine which one is bigger.
Input Format
Your inputs are two strings where the measurements for height and width are separated by a comma. The first one represents apartment A, the second represents apartment B.
Output Format:
A string that says whether apartment A or apartment B has a larger balcony.
Sample Input
'5,5'
'2,10'
Sample Output
Apartment A
* Not sure why you are using a for loop for ... as this is just comparing the size of apartment A and apartment B...
int main() {
//set initializers
float h,w,A;
float h1,w1,B;
//input apartments height & width
cin>>h; getchar();
cin>>w;
cin>>h1; getchar();
cin>>w1;
//area of apartment A and B
A=h*w;
B=h1*w1;
+ 1
BroFar you have my thanks
0
#include <iostream>
#include <string>
using namespace std;
int main() {
string a, b;
cin>>a>>b;
int h,w,x,y;
for(int i=0; i<size(a);i++){
if(a.at(i)!="," && a.at(i+1)==","){
h=(int)a.substr(0,i+1);
w=(int)a.substr(i+2);
}
}
for(int i=0; i<size(b);i++){
if(b.at(i)!="," && b.at(i+1)==","){
x=(int)b.substr(0,i+1);
y=(int)b.substr(i+2);
}
}
if(x*y>h*w){
cout<<"Appartment B";
} else{
cout<<"Appartment A";
}
return 0;
}
0
I tried this but still gives me errors
0
BroFar My problem is that the input is 2 strings