1.)
You'll need a for loop (or a while loop) and three variables for the highest, average, and lowest. When the user inputs the first number, assign all three to that number, then go into your loop. In your loop add the next number to average, check to see if it's lower than lowest or higher then highest, and apply the correct operation. Repeat. After you're done, divide the average (which is a sum at this point) by the number of numbers entered. Display.
2.)
There are so many ways you could implement this, you should tell me your ideas first.
1.) give me a sample code/syntax? uhm.. i kinda had gone as far as doin all except for the part of displaying the high and low.
i kinda have no idea on how will i assign the inputs of the user.
2.)
my i dea would be like this..
the user will input 10 names (the code will be a loop one)
n1 will determine how many names the user will input like for(i=0;i<=n1;i++)
and it will be displayed ALPHABETICALLY ARRANGED
like for example
if he enter 3 names and it goes like this
how many names: 3
enter name: robert
enter name : matt
enter name : cedrick
int numOfNums;
int high;
int low;
int sum;
//get number of numbers
//get first number
//set all above variables to that input
for(int x = 1; x < numOfNums; x++)
{
//get input
//if number is highest or lowest, set the correct one
//add input to sum
}
//display output
You're going to have to try to work with me. That was some generous skeleton code.
6 Tell user to enter the number of numbers they are going to enter, then get input from the user (2-3 of your code).
8 Tell user to enter the first number. Get input from the user.
9 Set the highest, lowest, and sum variables to that number.
14 If the number the user input is greater than the highest number, set the highest to that number. If the number the user input is less than the lowest number, set the lowest to that number.
15 Add the number to the running sum.
When you are done with the for loop, the average is the sum divided by the number of numbers.
2.)
Declare an array of 10 strings. Get the user input for each String. Sort the array using your own defined sort method, or look up a sort method. I can't remember which one comes with all versions of C++.
thats the problem i dont know how to do that :( our prof was kinda "hey do...while is for loop control structure, so make a program using it" and we were just like "how the hell would we do that if you just say that do...while is a loop control structure."
that's what our situation in school is kind of. so i really have no idea XD
2.
array of 10 strings? like:
1 2
int = n[10];
would it be like that? err.. im not so sure about it XD
about the sort method thats THE REAL DEAL our prof ddnt even bother to told us how to use or make a sorting program all he says that a control structure can also be use for sorting in methods of binary and etc. -_-
I really can't give you any more on number one without giving you the answer. Your code has all the syntactical stuff, so you just need to use what you know to get to what I told you about.
An array allows you to store the names without using ten variables and there are sort functions that you can use to sort an array. You can't sort variables.
but in number 1.) i kind of having a problem with the product
you see my intention in line 9 was to multiply all the numbers that the user inputs but as i try to run the program i dont know where the heck the program gets his multiplier, the program gave me a product of i dont know where did it come from.
number 2.) uhm i dont know how would array help me here..
you see i really dont know how would the user inputs the name, lets say he inputs
x
c
a
d
h
b
s
with that given input how would the array work to sort that and make it alphabetical arrange that would look like this.
I do want to point out that you will most likely want to use a while loop since that is what your professor is asking for. How you go about making that while loops all depends on your taste.
I can't add on to GRex's code without, again, giving you the answer -- But what I can say is I think you are losing sight and relying too much on your professor to tell you what to do. Remember that in programming you are going to have to think outside the box. From the instructions you have presented to us, I see no need for the product of any of the numbers.
As for your second problem.. You will find it more beneficial to create your own alphabetizing system versus looking one up. An array is going to help you because it is a lot cleaner and more organized than making 10 different variables (Which would be a lot of coding that you don't really need).
I am curious to know, do you know what an array is?
on number one i actually had made the program to be honest but the only problem i got is the product and displaying the highest and lowest
and as for array...
im thought of my prof that an array can be used so that you dont have to declare a lot of assignments and that it can be used for sorting (to which he ddint tell us how), that's all nothing more.
The program your prof wants is the average, so where is the product coming from?
An array by itself will not do the sorting for you, you have to figure that part out. Did your professor tell you anything about how to use arrays in any way shape or form? I would assume so, and if not there are tutorials that can help you:
He wants the lowest, average, highest, and product of all the numbers? Just create another variable that does what sum does, except it gets the product.
product *= num;
in the loop.
Use the tutorial, make an array of ten strings, sort using any sorting algorithm.
I knew you could do it. Just a few problems with your implementation. I edited your code below. You will have to do the product yourself. What I did with the variables isn't important (except for the sum and product). I just like declaring my variables on their own line and keeping temporary variables temporary.
#include<iostream>
usingnamespace std;
int main()
{
//int i,a1,num1,high,low,sum,prod,ave;
int a1;
int num1;
int high;
int low;
int sum = 0;
int prod = 1;
int ave;
cout<<"a"<<endl;
cin>>a1;
for(int i=1;i<=a1;i++)
{
cout<<"Enter the number: ";
cin>>num1;
//sum=num1+num1; when the loop finishes you'll just get the last number * 2
sum += num1;
//prod=num1*num1; when the loop finishes you'll just get the last number squared. Can you use the solution for sum to fix this?
//ave=sum/a1; wrong place for this
}
//this should be here
ave = sum / a1;
cout<<prod<<" "<<sum<<" "<<ave<<endl;
system("pause");
return 0;
}
To implement your high and low, you'll need to put one of the inputs outside the loop, then set high and low to the first input. You'll adjust them as needed in the loop.
o. k so i have to set an initial value for them to work.
i get them to work properly.
just the high and low this time.
how would i put one of the inputs outside the loop?
then set high and low to the first input?
and adjust them as needed in the loop?
would it be like this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cout<<"a"<<endl;
cin>>a1;
for(int i=1;i<=a1;i++)
{
cout<<"Enter the number: ";
cin>>num1;
//sum=num1+num1; when the loop finishes you'll just get the last number * 2
sum += num1;
//prod=num1*num1; when the loop finishes you'll just get the last number squared. Can you use the solution for sum to fix this?
//ave=sum/a1; wrong place for this
}
cout<<"enter...."; //should it go like this?
cin>>n2; // this is the outside of the loop input
ave = sum/a1;
and ooh btw i still have no.2 as a problem i havent started that yet i would be really thankful if you could help me on that too but of course after i have solved no.1 XD
btw i have read about the sorting of the array
there is this flag and temp
1 2 3
temp=n1[];
n1[]=n2[];
n2[]=temp;
im not sure if that it is how suppose to go cuz i havent placed may attention to number 2. yet