Bit of help required still - using a function with array

This is a discussion on Bit of help required still - using a function with array within the C++ Programming forums, part of the General Programming Boards category; Sorry I pasted an earlier code before fixing it, this one compiles but I can't figure out how to make ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    6

    Bit of help required still - using a function with array

    Sorry I pasted an earlier code before fixing it, this one compiles but I can't figure out how to make the values go through my function, or if I made it correctly to change input from user into celsius.


    Code:
    // Computer Lab test.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    double c;
    double celsius;
    double CheckCent(double c)
    {
        if ( c>30 )
        {
            return 1.8 * celsius + 32;
        }
    	return c;
    }
    
    
    // call this function to convert celsius to fahrenheit (function name is convert)
    int _tmain(int argc, _TCHAR* argv[])
    {
    double myarray[51];
    //double i;
    int flag;
    flag=1;
    int i;
    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;
    cout <<"\n";
    
    		return 0;
    }
    Last edited by Planetx33; 04-05-2007 at 05:57 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    So apart from not compiling, what do you want us to do with than unindented mess?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    6
    edited post

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    So, call the function?

    And don't use globals. The first one is not even what you think. The second one seems uninitialized.
    Code:
    //double c;
    //double celsius;
    double CheckCent(double c)
    {
        double celsius = ?;
        if ( c>30 )
        {
            return 1.8 * celsius + 32; //1.8 * c + 32 ?
        }
    	return c;
    }
    _tmain() and "stdafx.h" are MSVC specific stuff, I think, so your code doesn't compile for many.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    > if ( c>30 )
    And what do you return if it's <= 30?
    The maths works on all values, so why bother with this condition.

    You didn't fix the lack of indentation with your edit.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Basically the same question here as well
    Array Help Please (user defined size)
    Closed (& read the rules)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21