Wrox Programmer Forums
|
Visual C++ 2005 For discussion of Visual C++ 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 4th, 2007, 11:01 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with arrays please

I have having a bit of trouble, i need to write a program that converts fahrenheit to celsius (i can do the function for this part) but it needs to start with a loop that first prompts the user to "Enter Temperature:" and then stores the value entered into the array which is supposed to be no more than 50. I am having issues with how to input data into the array starting at 0 and keep going up 1 (all I can do is input data directly to myarray[50], but I want the user to input data and it be entered into the array like
enter data one > put in array[0]
enter data 2 > put in array[1]
The program also has to ask the user if they want to keep entering data by pressing 1, or stop by pressing 0. The program then has to display how many arrays there are of temperatures (not the value of them, just how many there are). Please help!! This is what I have so far, any help greatly appreciated.

// Computer Lab test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

// call this function to convert celsius to fahrenheit (function name is convert)
double
convert(double celsius){
   double fahrenheit = ((9.0/5.0) * celsius) + 32;
    return fahrenheit;
};

int _tmain(int argc, _TCHAR* argv[])
{
    double myarray[50];
    int flag;
    flag =1;
    while (flag==1)
    {
        // loop
        cout << "Enter Temperature Reading:";
        cin >>myarray[50]
    ;cout << " Enter 1 to input more values, 0 to stop";
    cin >>flag;
    }
    return 0;
}



 
Old April 5th, 2007, 02:06 AM
Registered User
 
Join Date: Apr 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, so 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 <iostream>
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;
}









Similar Threads
Thread Thread Starter Forum Replies Last Post
Help With Arrays Crippy Ruby 2 March 6th, 2013 05:59 PM
arrays ozPATT Excel VBA 2 November 4th, 2005 06:11 AM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM
Arrays tajin Excel VBA 0 June 20th, 2004 09:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.