-
Short C++ Assignment
Hey all...
I need to make a program to do the following...:
1) prompt a user to enter a set of data, one at a time, and store these in an array, using "while" loop. The numbers must be of "float" type.
2) Inform the user about the maximum number of data, and what to do when the last data point has been entered
3) Write, to standard output, the data that were entered
4) Write, again to standard output, a table containing the # of data points and the sum of data points.
Here's what I have
Code:
#include <iostream>
#include <stdio>
main ()
int numbers;
std::cin >> number;
int numbers[10];
while(numberCount < 10)
{
... I'm stuck!
}
std::cout << "Enter any letter if there is no more point to enter.";
I know this is terribly incomplete, but I've never used C++ before and I'm googling my way about here... any help please?
-
Look into cin - it's how you get input from the user. If you know how to use a while loop, your array, cin and cout, you should just be able to follow the numbered instructions you listed. Just so you know - you're question is entirely too vague - please don't post and expect anyone to write the code for you. You really need to ask specific questions and show us that you've done your part.
-
1.What does the function oldModString() do?
2. What are any issues or problems that you see with it?
3. How could you improve the function, and what benefits would your improvements bring?
4. What other additional improvements could you make to the rest of the code?
plz help me with above questions.
-
Ok, I totally redid it. Here is what I have
Code:
#include<iostream.h>
#include<math.h>
main()
{
int i;
float a[5],sum=0;
cout<<"\n Enter 5 numbers:\n\t\t\t";
for(i=0;i<5;i++)
{
if(i==4)
{
cout<<"\n You are entering the last number:\n\t\t\t";
}
cin>>a[i]; cout<<"\n\t\t\t";
sum+=a[i];
}
{
cout<<"\n The number of data: 5\t\t";
cout<<"\n The sum is:\t\t"<<sum;
cout<<"\n The average is:\t"<<(sum/5) ;
}}
I'm having the following troubles: I can't get the cout to print the entered data, and also, I wish to extend this program to enable any number of data to be entered, not just "5". This means I would have to signal the program to let it know when the last datum has been entered. Can you help me with this?
-
You should indent your code properly. Furthermore, you used <iostream>, which is correct, but now you changed it to <iostream.h>, which is pre-standard and should be avoided. As far as I can tell, you do not need to include <math.h>, and if you did, it should be <cmath>.
-
The main function must also return int. Any modern C++ compiler will refuse to compile the code unless every function has a proper return type.