Still need a bit of help please
-
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; }
-
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; }
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 forcout << "Number of elements in the array is: " << i;
Nibu thomas A Developer Programming tips[^] My site[^]
-
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 forcout << "Number of elements in the array is: " << i;
Nibu thomas A Developer Programming tips[^] My site[^]
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.
-
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.
-
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.
-
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.
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