I'm going to assume you mean smallest number to largest number for this; This seems like an assignment, so I'll let you implement it yourself, but a very easy way to sort, in this case, bubble sorting, can be used:
The idea is that you can run through an array of values, and "swap" the smaller ones with larger ones a number of times until they are sorted appropriately.
The above is called a bubble sort, very simple, not always the most efficient, but for smaller programs like this it could be implemented and used. You should also check out sorting methods like selection sort, merge sort, etc etc.
Why do you have used for each item a different array? If you sort one of this arrays, you need to re-arrange the order of the others. A better way would be, grouping all items of a record together, maybe into a struct.
#include <iostream>
#include <iomanip>
int main()
{
std::cout << "\nGRAMS OF FAT" << std::endl;
//Arrays and variables
std::string Days[5] = {"Day 1: ", "Day 2: ", "Day 3: ", "Day 4: ", "Day 5: "};
int GFats[5],
total;
//USER ENTERS NUMBERS TO DAYS
for (int i = 0; i < 5; ++i)
{
int Fats;
std::cout << "Enter number of grams of fat consumed on " << Days[i];
std::cin >> Fats;
GFats[i] = Fats;
}
for (int i = 0; i!=5; i++)
{
std::cout << std::endl <<Days[i] << GFats[i];
}
std::cout << std::endl << "Total Fats:" << GFats[0]+GFats[1]+GFats[2]+GFats[3]+GFats[4] << std::endl;
std::cout << "\nPROTEINS" << std::endl;
//second array
std::string Days_2[5] = {"Day 1: ", "Day 2: ", "Day 3: ", "Day 4: ", "Day 5: "};
int GProteins[5],
total_2;
//USER ENTERS NUMBERS TO DAYS
for (int i = 0; i < 5; ++i)
{
int Proteins;
std::cout << "Enter number of proteins consumed on " << Days_2[i];
std::cin >> Proteins;
GProteins[i] = Proteins;
}
for (int i = 0; i!=5; i++)
{
std::cout << std::endl << Days_2[i] << GProteins[i];
}
std::cout << std::endl << "Total proteins:" << GProteins[0]+GProteins[1]+GProteins[2]+GProteins[3]+GProteins[4] << std::endl;
std::cout << "\nRESULTS" << std::endl;
std::cout << "Total proteins:" << GProteins[0]+GProteins[1]+GProteins[2]+GProteins[3]+GProteins[4] << std::endl;
std::cout << "Total Fats:" << GFats[0]+GFats[1]+GFats[2]+GFats[3]+GFats[4] << std::endl;
}
I added this to have each day with the number that the user inputs
1 2 3 4
for (int i = 0; i!=5; i++)
{
std::cout << std::endl << Days_2[i] << GProteins[i];
}
GRAMS OF FAT
Enter number of grams of fat consumed on Day 1: 5
Enter number of grams of fat consumed on Day 2: 5
Enter number of grams of fat consumed on Day 3: 5
Enter number of grams of fat consumed on Day 4: 5
Enter number of grams of fat consumed on Day 5: 5
Day 1: 5
Day 2: 5
Day 3: 5
Day 4: 5
Day 5: 5
Total Fats:25
So according to Tduck I could use a bubble sort to sort the values of the days right?
and I have to use arrays, I would have preferred using other method but :(