Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with vector/array

Help with vector/array

Scheduled Pinned Locked Moved C / C++ / MFC
iosdatabasegraphicsdata-structureshelp
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    klutez123
    wrote on last edited by
    #1

    I need help with the following code that will also output the warmest and coldest days entered: // Compiler Directives #include "stdafx.h" #include "hightemp.h" #include #include #include #include #include // Global Declarations using namespace std; CWinApp TheApp; /***************************************************** * MAIN * *****************************************************/ int main() { vector daily_temp(31,0); // array of daily high temperatures int num_values; // number of days in a row to enter values int index; // index for loop counter and array access double average_high; // calculated average high temperature int total = 0; // used to total temps before averaging do // loop to ask for number of days until valid input is received { cout << "Enter the number of days for which you have data: "; cin >> num_values; if ((num_values < 1) || (num_values > 31)) { cout << "The number of days must be in the range 1 to 31" << endl; } } while ((num_values < 1) || (num_values > 31)); // The following loop gets the high temperatures from the user for as // many days as the user specified in num_values. for(index = 0; index <= (num_values - 1); index++) { cout << "Enter the high temperature for day " << index + 1 << ": "; cin >> daily_temp[index]; // input value into array } // Print the values in the array to the screen. cout << "The array contains high temperatures for " << num_values << " days.\n"; cout << "The values are as follows.\n"; for(index = 0; index <= (num_values - 1); index++) { cout << "Day " << index + 1 << ": " << daily_temp[index] << endl; total = total + daily_temp[index]; // update total for averaging } // Calculate average by typecasting total and num_values to doubles // before dividing and assigning the result to average_high. average_high = double(total) / double(num_values); // Print the results to the screen. cout.setf(ios::fixed); cout << "The average high temperature during the " << num_values << "-day period was " << setprecision(2) << average_high << " degrees.\n"; return 0; }

    P D S 3 Replies Last reply
    0
    • K klutez123

      I need help with the following code that will also output the warmest and coldest days entered: // Compiler Directives #include "stdafx.h" #include "hightemp.h" #include #include #include #include #include // Global Declarations using namespace std; CWinApp TheApp; /***************************************************** * MAIN * *****************************************************/ int main() { vector daily_temp(31,0); // array of daily high temperatures int num_values; // number of days in a row to enter values int index; // index for loop counter and array access double average_high; // calculated average high temperature int total = 0; // used to total temps before averaging do // loop to ask for number of days until valid input is received { cout << "Enter the number of days for which you have data: "; cin >> num_values; if ((num_values < 1) || (num_values > 31)) { cout << "The number of days must be in the range 1 to 31" << endl; } } while ((num_values < 1) || (num_values > 31)); // The following loop gets the high temperatures from the user for as // many days as the user specified in num_values. for(index = 0; index <= (num_values - 1); index++) { cout << "Enter the high temperature for day " << index + 1 << ": "; cin >> daily_temp[index]; // input value into array } // Print the values in the array to the screen. cout << "The array contains high temperatures for " << num_values << " days.\n"; cout << "The values are as follows.\n"; for(index = 0; index <= (num_values - 1); index++) { cout << "Day " << index + 1 << ": " << daily_temp[index] << endl; total = total + daily_temp[index]; // update total for averaging } // Calculate average by typecasting total and num_values to doubles // before dividing and assigning the result to average_high. average_high = double(total) / double(num_values); // Print the results to the screen. cout.setf(ios::fixed); cout << "The average high temperature during the " << num_values << "-day period was " << setprecision(2) << average_high << " degrees.\n"; return 0; }

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      Can you tell what problem you are facing ?

      Prasad Notifier using ATL | Operator new[],delete[][^]

      K 1 Reply Last reply
      0
      • P prasad_som

        Can you tell what problem you are facing ?

        Prasad Notifier using ATL | Operator new[],delete[][^]

        K Offline
        K Offline
        klutez123
        wrote on last edited by
        #3

        I have no problem with the code when compiled, I just need help on how to output the high and low temperature

        M 1 Reply Last reply
        0
        • K klutez123

          I have no problem with the code when compiled, I just need help on how to output the high and low temperature

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          Each time you enter a new temperature, you check with the previous one entered if it is bigger or lower.


          Maximilien Lincourt Your Head A Splode - Strong Bad

          1 Reply Last reply
          0
          • K klutez123

            I need help with the following code that will also output the warmest and coldest days entered: // Compiler Directives #include "stdafx.h" #include "hightemp.h" #include #include #include #include #include // Global Declarations using namespace std; CWinApp TheApp; /***************************************************** * MAIN * *****************************************************/ int main() { vector daily_temp(31,0); // array of daily high temperatures int num_values; // number of days in a row to enter values int index; // index for loop counter and array access double average_high; // calculated average high temperature int total = 0; // used to total temps before averaging do // loop to ask for number of days until valid input is received { cout << "Enter the number of days for which you have data: "; cin >> num_values; if ((num_values < 1) || (num_values > 31)) { cout << "The number of days must be in the range 1 to 31" << endl; } } while ((num_values < 1) || (num_values > 31)); // The following loop gets the high temperatures from the user for as // many days as the user specified in num_values. for(index = 0; index <= (num_values - 1); index++) { cout << "Enter the high temperature for day " << index + 1 << ": "; cin >> daily_temp[index]; // input value into array } // Print the values in the array to the screen. cout << "The array contains high temperatures for " << num_values << " days.\n"; cout << "The values are as follows.\n"; for(index = 0; index <= (num_values - 1); index++) { cout << "Day " << index + 1 << ": " << daily_temp[index] << endl; total = total + daily_temp[index]; // update total for averaging } // Calculate average by typecasting total and num_values to doubles // before dividing and assigning the result to average_high. average_high = double(total) / double(num_values); // Print the results to the screen. cout.setf(ios::fixed); cout << "The average high temperature during the " << num_values << "-day period was " << setprecision(2) << average_high << " degrees.\n"; return 0; }

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            klutez123 wrote:

            // The following loop gets the high temperatures from the user for as // many days as the user specified in num_values. for(index = 0; index <= (num_values - 1); index++) { cout << "Enter the high temperature for day " << index + 1 << ": "; cin >> daily_temp[index]; // input value into array }

            How about:

            int low = 500;
            int high = -500;

            for (index = 0; index <= (num_values - 1); index++)
            {
            cout << "Enter the high temperature for day " << index + 1 << ": ";
            cin >> daily_temp[index];

            if (daily\_temp\[index\] > high)
                high = daily\_temp\[index\];
            else if (daily\_temp\[index\] < low)
                low = daily\_temp\[index\];
            

            }


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • K klutez123

              I need help with the following code that will also output the warmest and coldest days entered: // Compiler Directives #include "stdafx.h" #include "hightemp.h" #include #include #include #include #include // Global Declarations using namespace std; CWinApp TheApp; /***************************************************** * MAIN * *****************************************************/ int main() { vector daily_temp(31,0); // array of daily high temperatures int num_values; // number of days in a row to enter values int index; // index for loop counter and array access double average_high; // calculated average high temperature int total = 0; // used to total temps before averaging do // loop to ask for number of days until valid input is received { cout << "Enter the number of days for which you have data: "; cin >> num_values; if ((num_values < 1) || (num_values > 31)) { cout << "The number of days must be in the range 1 to 31" << endl; } } while ((num_values < 1) || (num_values > 31)); // The following loop gets the high temperatures from the user for as // many days as the user specified in num_values. for(index = 0; index <= (num_values - 1); index++) { cout << "Enter the high temperature for day " << index + 1 << ": "; cin >> daily_temp[index]; // input value into array } // Print the values in the array to the screen. cout << "The array contains high temperatures for " << num_values << " days.\n"; cout << "The values are as follows.\n"; for(index = 0; index <= (num_values - 1); index++) { cout << "Day " << index + 1 << ": " << daily_temp[index] << endl; total = total + daily_temp[index]; // update total for averaging } // Calculate average by typecasting total and num_values to doubles // before dividing and assigning the result to average_high. average_high = double(total) / double(num_values); // Print the results to the screen. cout.setf(ios::fixed); cout << "The average high temperature during the " << num_values << "-day period was " << setprecision(2) << average_high << " degrees.\n"; return 0; }

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              We can't see many of the < or > characters in you post or what's between them; please revise and correct your post.

              Steve

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups