CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    25

    C++ Coding Help Me



    I am new to c++ and need some help.

    I need to create a code that asks the user

    How many numbers would you like to Enter?

    and then the user enters them one at a time.

    And the program is supposed to give

    the smallest , Largest , Average and the difference

    between each number and the average.

    I have done a bit of he code but it doesnt work...

    Could you help create this code......But in as simple code as possible as

    i am very new to programming....

    Thank You for reading

    #include <iostream.h>

    #include <conio.h>

    main()

    {

    clrscr();

    int a,b,min;

    cout<<"How many numbers would you like to enter?\t";

    cin>>a;

    {

    cout<<"Enter a number please:\t";

    cin>>b;

    for (int count=1;count<=a;count=count+1)

    if (count==1) min=b;

    if (b<min) min=b;

    }

    cout<<"Smallest number is\t"<<min;

    getch();

    return 0;

    }




  2. #2
    Join Date
    Apr 1999
    Posts
    90

    Re: C++ Coding Help Me



    Here's a start:

    main()

    {

    clrscr();

    int a,b,min,max,avg,sum=0;

    cout<<"How many numbers would you like to enter?\t";

    cin>>a;

    for (int count = 0; count < a; count++)

    {

    cout<<"Enter a number please:\t";

    cin>>b;

    sum += b;

    if (count == 0)

    {

    min = max = b;

    }

    else

    {

    if (b < min)

    min = b;

    if (b > max)

    max = b;

    }

    }

    avg = sum / a;

    cout<<"Smallest number is\t"<<min;

    getch();


    cout<<"Largest number is\t"<<max;

    getch();


    return 0;

    }



  3. #3
    Join Date
    Apr 1999
    Posts
    90

    Re: C++ Coding Help Me



    No problem.

    After some experience, you'll be able to whip problems like that out in no time! Now, if I could just master MFC, COM, ATL, etc...

  4. #4
    Join Date
    May 1999
    Posts
    123

    Re: C++ Coding Help Me



    To do this, you'll have to store all the numbers as you receive them. You can figure the min, max and average without storing the numbers, but you can't figure the difference between each number and the averge until you have the final average, which you don't have until all the numbers are entered.


    Since you're letting the user enter the number of entries (s)he's going to make, you can use that to allocate space to store the numbers. You'll have a structure something like this:


    define a pointer to a double

    ask the user for number of entries

    double_pointer = new int[num_entries];

    do a loop reading in one entry at a time into pointer[i]

    figure your statistics from the array of doubles

    print out the results.



  5. #5
    Join Date
    Mar 1999
    Posts
    1

    Re: C++ Coding Help Me



    Make him do his own homework, spoon feeding produces moronic programmers

  6. #6
    Join Date
    Apr 1999
    Posts
    25

    Re: C++ Coding Help Me



    Thank YOU to all who helped. I was in a jam but your responces helped me alot.

    To the guy who wrote HOMEWORK.

    I am not being spoon fed. I am sure you have had problems where somebody

    gave you a hand. Well this time I needed a hand and some good people helped

    me. Maybe oneday I can help somebody with simmilar problems.


    Thank You Guys again....

  7. #7
    Join Date
    Apr 2001
    Posts
    13

    Re: C++ Coding Help Me

    #include <iostream.h>
    #include <conio.h>

    main()
    {
    //clrscr();
    int a,b,min;
    cout<<"How many numbers would you like to enter?\t";
    cin>>a;

    cout<<"Enter a number please:\t";
    cin>>min;
    for (int count=2;count<=a;count=count+1)
    {
    //if (count==1) min=b;
    cout<<"Enter a number please:\t";
    cin>>b;
    if (b<min) min=b;
    }
    cout<<"Smallest number is\t"<<min;
    getch();
    return 0;
    }
    this is the code for finding the smallest integer
    u can modify it for other things.

    it's better u should trace wat u do.
    it'll help u a lot

    enjoy


    Mahesh Kumar C D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured