943,972 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2708
  • C++ RSS
Oct 4th, 2004
0

how to do something special with this question

Expand Post »
i have got to write a program to read a set of program n print out the average.
it will start by prompting the user for the number of numbers to be read and will then prompt for the individual numbers with a prompt such as Enter Number 23 to indicate to thr user which data item is currently being entered.now all that is easy but i have to do something special when prompting for the last number.here is what io have done but am unable to include the special thing for the last number have tried to put it in the loop an its displaying me 6 time the cout<<"enter the last number".i have written this program the way my lecturer has teach us.here is the program


// program to read set of number and print out their average
#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,n,x,sum;
float average;

cout<<"Enter the number of numbers to be read"<<endl;
cin>>n;

sum=0;
for(i=1;i<=n;i++)
{
cout<<"Enter number"<<endl;
cin>>x;

sum=sum+x; }

average=sum/n;

cout<<"the average of the numbers is"<<average<<endl;

getch();

}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pratima is offline Offline
7 posts
since Sep 2004
Oct 4th, 2004
0

Re: how to do something special with this question

you need to use an if statement in there to compare i and n,
if (i==n)
cout<<"Enter Last"<<endl;
else
cout<<"Enter Next"<<endl;

note the == in c/c++/java/javascript is a comparision if you had a single = it would assign i to n not compare.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clartsonly is offline Offline
15 posts
since Oct 2004
Oct 5th, 2004
0

Re: how to do something special with this question

>i have written this program the way my lecturer has teach us.
You have my sympathy, your lecturer is a moron and clearly doesn't know enough to be teaching.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 12th, 2004
0

Re: how to do something special with this question

Quote originally posted by Narue ...
>i have written this program the way my lecturer has teach us.
You have my sympathy, your lecturer is a moron and clearly doesn't know enough to be teaching.
you are a funny man, when do you actually help.....

I have to agree the romanian girl has spelling problems with the english language, but I had to order my sausage and egg Burger King breakfast three times before the lady knew what I was talking about, this morning and that was in euston london..

also I am shit at english and do not believe it is a core part of writing application code, as most of the books I have read were reference guides. apart from "the story of O" of course....

stay safe....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clartsonly is offline Offline
15 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Establishing A connection between Three programs.
Next Thread in C++ Forum Timeline: compiler





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC