One dimesional array
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: One dimesional array

  1. #1
    Join Date
    Aug 2010
    Posts
    51

    One dimesional array

    I am wanting the program to ask the user to enter a number from 1-10. When the user enters the number 1, the program should update only the first price in the array. When the user enters the number 2, the program should update only the second price in the array and so on.

    here is what i have so far(im am stuck at the cout statement on how to write the statement correctly to do the above instructions ^^^^)

    #include <iostream>
    #include <iomanip>
    using namespace std;

    int main()
    {
    cout << fixed << setprecision(2);

    //declare array
    double prices[10] = {10.5, 25.5, 9.75, 6.0, 35.0, 100.4, 10.65, .56, 14.75, 4.78};

    //declare variable
    double num = 0.0;

    //get number
    cout<<" Enter a number (1-10): ";
    cin>>num;








    return 0;
    } //end of main function

    any suggestions on how to code that part?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,423

    Re: One dimesional array

    Quote Originally Posted by ade161 View Post
    I am wanting the program to ask the user to enter a number from 1-10. When the user enters the number 1, the program should update only the first price in the array. When the user enters the number 2, the program should update only the second price in the array and so on.
    How do you access one element in the array?

    Given that answer, how do you take the number inputted and change that element in the array?

    Given that answer, how do you output that particular element in the array?

    If you can't get past the first question, I suggest you study what an array is, how to access elements in the array, etc. since what is asked of you in the assignment can't be more elementary.

    Regards,

    Paul McKenzie

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center