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<iostream>
-
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<=two;i++)
-
cout<< i <<endl;
-
for (int i=1; i<=two; i++)
-
sum = sum + i;
-
cout<<sum/i<<endl;
-
}else{
-
for(j=two;j<=one;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
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 -
if (one == two || one+1 == two || one == two+1 ) {
-
-
/* nothing to do */
-
return 0;
-
}
-
-
if (two < one) {
-
-
/* make sure one < two */
-
double tmp;
-
tmp = one;
-
one = two;
-
two = tmp;
-
}
-
-
for (i=one+1; i<two; i++) {
-
-
cout << i << endl;
-
sum = sum + i;
-
}
-
-
cout << sum/(two-one-1) << endl;
-
Note that I changed the conditions in the loop and the divisor for the average.
wo thnks alot! really helped...
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?
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>
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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( )
{
|
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.
|
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.
| |
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
|
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
|
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:
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |