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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Still need a bit of help please

Still need a bit of help please

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++data-structures
6 Posts 3 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.
  • P Offline
    P Offline
    planetx22
    wrote on last edited by
    #1

    Ok, so thanks to the help I have the program working somewhat correctly, I think. It has 2 loops, a for and while.. one allows the user to keep inputting data into an array that will be defined by the user in size but is no more than 50 values. I have a while loop in this that will ask user to input 1 to continue, 0 to stop entering temperatures. My problem is, I think the values are being stored correctly cause when i choose to output say myarray[0] the correct value I input comes up, but I want to be able to print out how many actual arrays there are in a statement like "Number of readings entered is 12," not the values in them (although I hope i stored each one properly). This is where I am stuck. From here I have to take the data and make sure its all in centigrade. Im pretty sure I can write a basic function to do this part, but how do I make a statement to call this in my loop as the user inputs functions, and then prints out how many there are? Any help much appreciated thanks. // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; int i; int flag; flag=1; for(i= 0; i < 50; i++) while (flag==1) { // loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; } std::cout << myarray[i] << std::endl; return 0; }

    N 1 Reply Last reply
    0
    • P planetx22

      Ok, so thanks to the help I have the program working somewhat correctly, I think. It has 2 loops, a for and while.. one allows the user to keep inputting data into an array that will be defined by the user in size but is no more than 50 values. I have a while loop in this that will ask user to input 1 to continue, 0 to stop entering temperatures. My problem is, I think the values are being stored correctly cause when i choose to output say myarray[0] the correct value I input comes up, but I want to be able to print out how many actual arrays there are in a statement like "Number of readings entered is 12," not the values in them (although I hope i stored each one properly). This is where I am stuck. From here I have to take the data and make sure its all in centigrade. Im pretty sure I can write a basic function to do this part, but how do I make a statement to call this in my loop as the user inputs functions, and then prints out how many there are? Any help much appreciated thanks. // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; int i; int flag; flag=1; for(i= 0; i < 50; i++) while (flag==1) { // loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; } std::cout << myarray[i] << std::endl; return 0; }

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      planetx22 wrote:

      for(i= 0; i < 50; i++) while (flag==1) { // loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }

      Modify the above code to the following...

      for(i = 0; i < 51 && flag == 1; i++)
      {
      // Loop to enter temperatures - pressing 1 continues, pressing 0 stops //
      cout << "Enter Temperature Reading:";
      cin >>myarray[i];
      cout << "Enter 1 to input more values, 0 to stop";
      cin >>flag;
      }// End for

      cout << "Number of elements in the array is: " << i;


      Nibu thomas A Developer Programming tips[^]  My site[^]

      P 1 Reply Last reply
      0
      • N Nibu babu thomas

        planetx22 wrote:

        for(i= 0; i < 50; i++) while (flag==1) { // loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }

        Modify the above code to the following...

        for(i = 0; i < 51 && flag == 1; i++)
        {
        // Loop to enter temperatures - pressing 1 continues, pressing 0 stops //
        cout << "Enter Temperature Reading:";
        cin >>myarray[i];
        cout << "Enter 1 to input more values, 0 to stop";
        cin >>flag;
        }// End for

        cout << "Number of elements in the array is: " << i;


        Nibu thomas A Developer Programming tips[^]  My site[^]

        P Offline
        P Offline
        planetx22
        wrote on last edited by
        #3

        Ahh.. of course I don't know why I didnt see that before thank you very much. The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius. Im just not sure how to make the computer know if the values entered are fahrenheit or not (i know the math formula, just not how to use it). Any help much appreciated thanks.

        N D 2 Replies Last reply
        0
        • P planetx22

          Ahh.. of course I don't know why I didnt see that before thank you very much. The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius. Im just not sure how to make the computer know if the values entered are fahrenheit or not (i know the math formula, just not how to use it). Any help much appreciated thanks.

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          planetx22 wrote:

          The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius.

          See here[^]


          Nibu thomas A Developer Programming tips[^]  My site[^]

          P 1 Reply Last reply
          0
          • N Nibu babu thomas

            planetx22 wrote:

            The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius.

            See here[^]


            Nibu thomas A Developer Programming tips[^]  My site[^]

            P Offline
            P Offline
            planetx22
            wrote on last edited by
            #5

            thanks alot.. got me on the right track i think. My function goes like - double my func(double fahrenheit) { if (fahrenheit>100) fahrenheit = 1.8 * celsius + 32; return fahrenheit; }; Im just not sure how to make the value the user enters into myarray[0-50] go into fahrenheit and then do the check, then return the value to the array either fixed with the formula or not because it was not greater than 100. Can I do something like in my for loop before the user chooses to continue or stop, or is that the wrong spot? And would it be something like - myarray[i]=my func(myarray[i]; ? Thanks alot for the help.

            1 Reply Last reply
            0
            • P planetx22

              Ahh.. of course I don't know why I didnt see that before thank you very much. The next thing I need to do is use a function i previously made to convert the values entered in array from fahrenheit (if they are) to celsius. Im just not sure how to make the computer know if the values entered are fahrenheit or not (i know the math formula, just not how to use it). Any help much appreciated thanks.

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

              planetx22 wrote:

              Im just not sure how to make the computer know if the values entered are fahrenheit or not...

              It can't. If you simply see 35o, how would you know whether its F or C? You might want to ask the user what they will be entering before the for loop.


              "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
              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