User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,377 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,038 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1837 | Replies: 3
Reply
Join Date: Sep 2004
Posts: 7
Reputation: pratima is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
pratima pratima is offline Offline
Newbie Poster

Solution how to do something special with this question

  #1  
Oct 4th, 2004
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();

}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2004
Posts: 15
Reputation: clartsonly is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
clartsonly clartsonly is offline Offline
Newbie Poster

Re: how to do something special with this question

  #2  
Oct 4th, 2004
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.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,333
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: how to do something special with this question

  #3  
Oct 5th, 2004
>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.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Join Date: Oct 2004
Posts: 15
Reputation: clartsonly is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
clartsonly clartsonly is offline Offline
Newbie Poster

Re: how to do something special with this question

  #4  
Oct 12th, 2004
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....
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 3:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC