Develop a C++ program to compare weights of two persons and displays the most weight between two using this pointer.
#include <iostream>
struct person {
std::string name;
double weight;
struct person(std::string name, double weight) {
this.name = name;
this.weight = weight;
}
};
int main()
{
struct person *a = new struct person("asdgfdg", 435.435);
struct person *b = new struct person("fdg", 34.435);
if (a->weight > b.weight)
std::cout << a.name << std::endl;
if (a->weight < b.weight)
std::cout << b.name << std::endl;
if (a.weight == b.weight)
std::cout << "They are the same weight" << std::endl;
return 0;
}
Comments
Leave a comment