473,834 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

gettin d average!!

29 New Member
write a program that will accept 2
integer numbers from the user and
then display out
all the integer
numbers in between
those two integers
excluding the two
numbers, then
display the avg
among the output
displayed.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. double one,two,i,j,sum=0,a,b;//declaring variables
  7.  
  8.  
  9. cout<< "first value = ";//ask for first num
  10. cin>>one;               //first input
  11. cout<<"second value = ";//ask for second num
  12. cin>>two;               //second input
  13.  
  14. cout<<'\n';             //skip a line
  15.  
  16.        if(two>one){
  17.             for(i=one;i<=two;i++)
  18.             cout<< i <<endl;
  19.                      for (int i=1; i<=two; i++)
  20.                      sum = sum + i;
  21.                      cout<<sum/i<<endl;
  22.        }else{
  23.             for(j=two;j<=one;j++)
  24.             cout<< j <<endl;
  25.                   }
  26.  
  27.  
  28.  
  29.     system("pause");
  30.     return 0;
  31. }


after this im stuck...i cant get the average part to work out rite! anyone able to help me out i can get it to sum up but i cant get it to divide so i'll get d average
Mar 18 '07 #1
4 1388
arne
315 Recognized Expert Contributor
write a program that will accept 2
integer numbers from the user and
then display out
all the integer
numbers in between
those two integers
excluding the two
numbers, then
display the avg
among the output
displayed.

#include<iostre am>
using namespace std;

int main()
{
double one,two,i,j,sum =0,a,b;//declaring variables


cout<< "first value = ";//ask for first num
cin>>one; //first input
cout<<"second value = ";//ask for second num
cin>>two; //second input

cout<<'\n'; //skip a line

if(two>one){
for(i=one;i<=tw o;i++)
cout<< i <<endl;
for (int i=1; i<=two; i++)
sum = sum + i;
cout<<sum/i<<endl;
}else{
for(j=two;j<=on e;j++)
cout<< j <<endl;
}



system("pause") ;
return 0;
}



after this im stuck...i cant get the average part to work out rite! anyone able to help me out i can get it to sum up but i cant get it to divide so i'll get d average

You were almost there. Try this
Expand|Select|Wrap|Line Numbers
  1.     if (one == two || one+1 == two || one == two+1 ) {
  2.  
  3.         /* nothing to do */
  4.         return 0;
  5.     }
  6.  
  7.     if (two < one) {
  8.  
  9.         /* make sure one < two */
  10.         double tmp;
  11.         tmp = one;
  12.         one = two;
  13.         two = tmp;
  14.     }
  15.  
  16.     for (i=one+1; i<two; i++) {
  17.  
  18.         cout << i << endl;
  19.         sum = sum + i;
  20.     }
  21.  
  22.     cout << sum/(two-one-1) << endl;
  23.  
Note that I changed the conditions in the loop and the divisor for the average.
Mar 18 '07 #2
1051109210
29 New Member
wo thnks alot! really helped...
Mar 18 '07 #3
melodyii
1 New Member
write a program that will accept 2
integer numbers from the user and
then display out
all the integer
numbers in between
those two integers
excluding the two
numbers, then
display the avg
among the output
displayed.

#include<iostre am>
using namespace std;

int main()
{
double one,two,i,j,sum =0,a,b;//declaring variables


cout<< "first value = ";//ask for first num
cin>>one; //first input
cout<<"second value = ";//ask for second num
cin>>two; //second input

cout<<'\n'; //skip a line

if(two>one){
for(i=one;i<=tw o;i++)
cout<< i <<endl;
for (int i=1; i<=two; i++)
sum = sum + i;
cout<<sum/i<<endl;
}else{
for(j=two;j<=on e;j++)
cout<< j <<endl;
}



system("pause") ;
return 0;
}



after this im stuck...i cant get the average part to work out rite! anyone able to help me out i can get it to sum up but i cant get it to divide so i'll get d average

owH! U donT use Printf and scanf?
Mar 19 '07 #4
Ganon11
3,652 Recognized Expert Specialist
printf and scanf are functions used mainly in C, but have been replaced by cout and cin in C++. You can still use scanf/printf if you include the header file <cstdio>
Mar 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1030
by: Phadnis | last post by:
hi i am not gettin images when iam using a proxy for internet explorer.. iam building a vb.net application for this. plz give some code samples. also how to implement the RFC for my proxy to work. iam very new to socket programming. n this task is urgent.. reply asap.. thks...
6
3140
by: J | last post by:
Kind of new at programming/vb.net. I'm doing this junky die roller program. Heres's what is supposed to happen: Roll 2 6-sided dies. Add rolls together put total in rolls(d6total). Display the number of 2 or 12 rolled, then display those numbers and average rolls. I didn't know how to do it exactly, but I came up with this.
4
3413
by: Gary | last post by:
Hi, I have a temperature conversion program down pat, but I was told to add an average, meaning, i need to get the average temperature for as many times as it was entered. i do not know where to start, and my stpid book doesnt seem to help. here is my program #include <iostream.h> void main( ) {
3
2319
by: C++Geek | last post by:
I need to get this program to average the salaries. What am I doing wrong? //Program to read in employee data and calculate the average salaries of the emplyees.
10
6968
by: PH | last post by:
Hi guys! I need to get the remote EndPoint from when I receive packets when listening in a local port in my computer. I'm using UDP (connection-less) so I only bind the socket to my localEndPoint, I do not Bind(), Connect() to a RemoteEndPoint.
3
4145
by: mochatrpl | last post by:
I am looking for a way to make a query / report display the running average for total dollars. I have already set up a query to provide totals dollars per day from which a report graphly shows the dollars per week. How do I then take the dollars and get a running average for the year? - Randy
3
5312
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average. Suppose that homework counts 10%, quizzes 20%, and tests 70%. If Pat has a homework grade of 92, a quiz grade of 68, and a test grade of 81, then
5
3186
by: p3rk3le | last post by:
So, I'm about to do a sequential search on a table (n contents) of random numbers. I have to print the average between the number of comparisons and the contents of the table (n) and the average time for each sequential search. I wrote:
1
8289
by: Ormazd | last post by:
Hello, I was wondering if anyone might be able to help me with a little PERL script? I'm very new and I have been given a task to write a simple Perl script that prints out the file names and file sizes and determines the average file size from the directory listing found in the "files.txt" file. In other words, I need to add up the size of all of the files listed in the text document and divide by the number of files listed. Sample of...
0
9800
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9651
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10516
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10225
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6961
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5630
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5802
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3987
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3085
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.