dimanche 4 juillet 2021

FInding the smallest value from a file in c++ that contains rows and column

for my study lesson, I have to find the highest and the smallest value from a file that has 30 rows and 5 columns but the value I need to find is just from column 3 to column 5. For the highest, I already get the answer however for the smallest I got 0 as the answer

#include <fstream>   

#include <iostream>

int main()
{
    std::ifstream ifs("read.txt");

if (!ifs)
    return (std::cout << "Cannot open file\n"), 1;



int highest_radius {};
int smallest_radius {};

int highest_diameter {};
int smallest_diameter {};

int highest_area {};
int smallest_area {};

for (int a {}, b {}, c {}, d {}, e {}; ifs >> a >> b >> c >> d >> e;)
{

    if (c > highest_radius )     
        highest_radius = c;
    if (d > highest_diameter )     
        highest_diameter = d;
    if (e > highest_area )      
        highest_area = e;

    if (c < smallest_radius )    
        smallest_radius = c;
    if (d < smallest_diameter )    
        smallest_diameter = d;
else if (e < smallest_area )    
        smallest_area = e;

}

   std::cout << "The highest radius value is " << highest_radius << '\n';
   std::cout << "The highest diameter value is " << highest_diameter << '\n';
   std::cout << "The highest area value is "  << highest_area << '\n';
   std::cout << "The smallest radius value is " << smallest_radius << '\n';
   std::cout << "The smallest diameter value is " << smallest_diameter << '\n';
   std::cout << "The smallest area value is "  << smallest_area << '\n';


} 

can anyone help me? I really appreciate it. Thank you so much

Aucun commentaire:

Enregistrer un commentaire