This is my code:
#include <iostream>
using namespace std;
int main()
{
int c, floor, colum;
float rent;
cout<<"\n\n\t\t\t\t< Sistema de calculo de arriendos >"<<endl<<endl<<endl;
cout<<"> Ingrese el valor de la renta: "<<char(36);
cin>>rent;
cout<<endl;
cout<<"> Ingrese la cantidad de pisos: ";
cin>>floor;
cout<<endl<<"> Ingrese la cantidad de habitaciones por piso: ";
cin>>colum;
cout<<endl<<endl;
string edificio[floor][colum];
int vpiso[floor];
for (int x=0, y=0; x<floor && y<=colum; y++)
{
if (y==colum)
{
y=0;
}
cout<<"> En el Piso "<<x+1<<" la habitacion "<<y+1<<" esta ocupada? (si/no): ";
cin>>edificio[x][y];
cout<<endl;
if (edificio[x][y]=="si")
{
c++;
}
if (y==colum-1)
{
x++;
}
}
cout<<"\n\n\t\t";
for (int x=0, y=0; x<floor && y<=colum; y++)
{
if (y==colum)
{
y=0;
}
cout<<edificio[x][y]<<"\t";
if (y==colum-1)
{
x++;
cout<<"\n\n\t\t";
}
}
cout<<endl<<"> Debe cobrar a "<<c<<" personas un valor de: "<<char(36)<<rent*c;
cin.get();
cin.get();
return 0;
}
PS: I redid the program from 0, but what I want is to show on the screen the value to be charged for each row
ex:
"On floor 1 they must" x people "and they have to pay" x value
"On floor 2 they must" x people "and they have to pay" x value
This is poorly worded, if you said "so many" or "so many" , it would be more understandable, but since you put the letter
x
it seems as if it were a variable.I would change it for this, since the number of people is not likely to be the same as the value to pay. The magic is in changing the floor number to that of a variable.
I suspect the variables should be...
The code should be something like this, below the
if
one that verifies the column should go acout
.Problem.
All. The code you present does not seem to fit, in any way, what you intend.
vpiso
not used.std::string
without including<string>
.std::cin
to ask a binary question to your user, using a text variable to read and check the result.std::endl
."En el piso 1 deben" x personas "y tienen que pagar" x valor
at the end and that string isn't even part of the code.Point 3 is especially worrying, all these answers will be considered negative:
Si
.SI
.Yes
.Da
.sí
.While these negative answers will be considered positive:
si claro, a ti te lo voy a decir!
.si vuelves a preguntarme algo, me comeré tu pez de colores a la parrilla
.si me entero de que trabajas para Skynet usaré tu CPU de pisapapeles
.Proposal.
You don't need a two-dimensional array to store each floor/room since you only need the sum of each floor, so use an array only for the rooms where you will count each occupied floor.
Unoccupied floors don't matter to us for the calculation, so we ignore them:
To finish, we show the results and free the dynamic memory:
You can see the code working [here] .