Jump to content

need help with C++ please!!!!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
january

january

    Newbie

  • Members
  • Pip
  • 2 posts
MY CODE ISNT WORKING AND I JUST DONT KNOW WHAT IS WRONG WITH IT PLEASE HELP ITS DRIVING ME NUTS.


//Write a function that verifies if a given number exists in an array of floats. The function is supposed to return the first position in where the number is encountered. If the given number does not exist, the function returns –1.Then write a program that asks the user to enter an array of floats and calls the function.//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int checkArray(float* ary, int numfloats);

int main()
{
    float* ary;
    int numfloats;
    int position;
    
    float ary[numfloats];

    printf("Enter the number of floats in the array:  ");
    scanf_s("%d",&numfloats);
    
    printf("Begin entering your values (floating points)\n");    
    for(int i = 0; i < numfloats; i++)
    {
        printf("Enter number %2d: ", i + 1);
        scanf_s("%d", &ary[i]);
    }//for
    float ary = (numfloats, ary);
        
    
    if (position >= 0)
       printf("The first occurance of the number is in position: %d\n", position);
    else
       printf("Error.This number does not appear in the array\n"); 
    getchar();
    return 0;
}
int checkArray(float* ary, int numfloats)
{
    float searchNum; 
    float precision;
    int position = -1;
    int num;
    
    printf("\nWhat number are you searching for?  ");
    
    scanf_s("%f", &searchNum);
    
    printf("\nEnter the precision you would like. ");
    printf("\nEnter 0 for exact values. ");
    scanf_s("%f", precision);
    for(num=0; num < numfloats; num++)
    {

Edited by WingedPanther, 20 March 2010 - 07:44 PM.
add code tags


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
I don't think you posted all your code.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog