Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

alfers101 Group Title

i have a program assignment. this is the problem: Input a number and store the integers of the number to the elements of the array. print the integers and the sum of the integers from the array. my program is wrong :( can someone help me please

  • 2 years ago
  • 2 years ago

  • This Question is Closed
  1. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    what programming language are you using? so at the moment what are you doing? using an array to store the numbers as the user enters them? then summing and outputting them after the user is done?

    • 2 years ago
  2. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    C++

    • 2 years ago
  3. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    this is my prog: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int x[0],sum=0,a,num,n; cout<<"How many number do you wish to add: "; cin>>a; cout<<"Enter the numbers: "; cin>>x[a]; for(int b=0;b<;b++) { cin>>x[b]; sum+=x[b]; cout<<"The sum of your numbers: "<<sum<<endl; } system("PAUSE"); return EXIT_SUCCESS; }

    • 2 years ago
  4. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    do you have any limitations on what you're allowed to do? for example are you allowed to use a list? or much you use an array?

    • 2 years ago
  5. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    no

    • 2 years ago
  6. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    i see so you are just having issues with creating the array int* array; int size; cout << "How many numbers would you like to enter?" << endl; cin >> size; and then when you want to create it array = new int[size]; and when you're done make sure you give back the memory delete [] array;

    • 2 years ago
  7. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    wait ill try that

    • 2 years ago
  8. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    done. here is my new program but how can i repeat the question "ENTER THE NUMBER" depending on the number u want to input?

    • 2 years ago
  9. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int array[0],sum=0; int size; cout << "How many numbers would you like to enter?"; cin >> size; cout<<"Enter your numbers "; for(int x=0;x<size;x++) { cin>>array[x]; sum+=array[x]; } cout<<"The sum is "<<sum; system("PAUSE"); return EXIT_SUCCESS; }

    • 2 years ago
  10. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    do you mean ask them to enter a number each time? you could output the statement in the for loop

    • 2 years ago
  11. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    done thank you !

    • 2 years ago
  12. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here is my another problem and LAST poblem: Write a program that will search for the largest and smallest value in array of integers of length 10.

    • 2 years ago
  13. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here is my program: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { float x[10],largest,smallest; cout<<"Enter a number "; cin>>x[0]; largest=x[0]; for(int a=0;a<10;a++) { cin>>x[a]; if(x[a]>largest) largest=x[a]; cout<<"The largest number is "<<largest; } else { (x[a]<largest) smallest=x[a]; cout<<"The smallest number is "<<smallest; } system("PAUSE"); return EXIT_SUCCESS; }

    • 2 years ago
  14. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int* array; int sum=0; int size; cout << "How many numbers would you like to enter?"; cin >> size; cout<<"Enter your numbers "; array = new int[size]; // init the array to for(int x=0;x<size;x++) { cin>>array[x]; sum+=array[x]; } cout<<"The sum is "<<sum; system("PAUSE"); delete [] array; // clean up the memory return EXIT_SUCCESS; }

    • 2 years ago
  15. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    oooops sorry ! thats wrong.

    • 2 years ago
  16. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here is the real program that i made: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { float x[10],largest,smallest; cout<<"Enter a number "; cin>>x[0]; largest=x[0]; for(int a=0;a<10;a++) { cin>>x[a]; if(x[a]>largest) largest=x[a]; cout<<"The largest number is "<<largest; } else { (x[a]<largest) smallest=x[a]; cout<<"The smallest number is "<<smallest; } system("PAUSE"); return EXIT_SUCCESS; }

    • 2 years ago
  17. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    ok i've looked at the code, where are you having problems ?

    • 2 years ago
  18. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    it doesnt run :(

    • 2 years ago
  19. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    you're missing some curly brackets { after the if(x[a]>largest) and } after cout<<"The smallest number is "<<smallest; and what's with (x[a]<largest) ?

    • 2 years ago
  20. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    actually im doing trial and error. :) but i cant print the largest and smallest number that entered

    • 2 years ago
  21. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    im done ! lol :D i did it

    • 2 years ago
  22. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    good work =)

    • 2 years ago
  23. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    but how can i repeat again "ENTER THE NUMBER" ??

    • 2 years ago
  24. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    here is my final program: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { float x[10],largest,smallest; cout<<"Enter a number "; cin>>x[0]; largest=x[0]; for(int a=1;a<10;a++) { cin>>x[a]; if(x[a]>largest) largest=x[a]; if(x[a]<smallest) smallest=x[a]; } cout<<"The largest number is "<<largest<<endl; cout<<"The smallest number is "<<smallest<<endl; system("PAUSE"); return EXIT_SUCCESS; } how can i repeat the "ENTER THE NUMBER" ??

    • 2 years ago
  25. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    put cout<<"Enter a number "; into the for loop

    • 2 years ago
  26. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    just it? or together with the cin>>x[0]; largest=x[0];??

    • 2 years ago
  27. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i didnt work. well actually it run but it double the number

    • 2 years ago
  28. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    like for(int a=1;a<10;a++) { cout<<"Enter a number "; cin>>x[a]; if(x[a]>largest) largest=x[a]; if(x[a]<smallest) smallest=x[a]; }

    • 2 years ago
  29. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the largest number didn't work.

    • 2 years ago
  30. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    that's strange from the code i can see it should have, one sec i'll compile it and have a look

    • 2 years ago
  31. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    the code you sent before is working fine =\

    • 2 years ago
  32. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    done :D

    • 2 years ago
  33. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    i did this: for(int a=0;a<10;a++) { cout<<"Enter a number "; largest=x[0]; cin>>x[a]; if(x[a]>largest) largest=x[a]; if(x[a]<smallest) smallest=x[a]; }

    • 2 years ago
  34. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    do have any facebook account? i will add u so that when i have another problem. i can ask u about it.

    • 2 years ago
  35. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    just ask on here that way if i'm not around anyone can help =)

    • 2 years ago
  36. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ok sure. wait i saw this problem here on my book. it says " Write a program that will print the seven positioned elements in an array of 10 floating numbers."

    • 2 years ago
  37. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    that confused me. what would be the program look like ?

    • 2 years ago
  38. mas_gh90 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    ndani14 helps everybody...how kind he is,don't you think so?he helped me a lot:))

    • 2 years ago
  39. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    yup i think he is really kind and helpful. God Bless him. Thank you again ndani14!

    • 2 years ago
  40. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    so you have an array of 10 floats and it wants to know how you would access the seventh element? eg. float myFloats[10]; myFloats[x]; // what should x be?

    • 2 years ago
  41. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    what does the "even positioned element" mean? the elements like: 2,4,6,8,10 elements?

    • 2 years ago
  42. alfers101 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the numbers that u input to the 2,4,6,8,10th element will print out ?? is that it ?

    • 2 years ago
  43. ndani14 Group Title
    Best Response
    You've already chosen the best response.
    Medals 2

    almost except arrays begin their indexing at 0 so the 1st element is 0, 2nd is 1 and so on

    • 2 years ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.