ok my program works the only thing i cant figure out how to do is, print the sum, average and the numbers (entered) in reverse order. after it tells my the real sum and average.

her is what i got so far

#include "stdafx.h";
#include <iostream>
#include <string>
using namespace std;

int numbers, sum, average;

int main()
{
    int numbers[5];
    double sum, average;
    int counter;
    cout <<"Enter five numbers: " << endl;
    sum = 0;
    for(counter = 0; counter < 5; counter++)
    {
        cin >> numbers[counter];
        sum = sum + numbers [counter];
        average = sum / 5;
    }
    cout << endl;
    cout <<"The sum of the numbers is : " << sum << endl;
    cout <<"The average of the numbers is: " << average;
    cout << endl;
    cout <<" "<< endl;

    return 0;
}

ok i got the numbers to print out in reverse order but i can getthe sum and average to print out in reverse order. anyone got anything for me.

#include "stdafx.h";
#include <iostream>
#include <string>
using namespace std;

int numbers, sum, average;

int main()
{
    int numbers[5];
    double sum, average;
    int counter;
    cout <<"Enter five numbers: " << endl;
    sum = 0;
    for(counter = 0; counter < 5; counter++)
    {
        cin >> numbers[counter];
        sum = sum + numbers [counter];
        average = sum / 5;
    }
    cout << endl;
    cout <<"The sum of the numbers is : " << sum << endl;
    cout <<"The average of the numbers is: " << average;
    cout << endl;
    cout <<" "<< endl;
    cout <<"The numbers you have entered reverse order: " << endl;
    cout << numbers[4] << endl;
    cout << numbers[3] << endl;
    cout << numbers[2] << endl;
    cout << numbers[1] << endl;
    cout << numbers[0] << endl;
    cout <<" "<< endl;

    return 0;
}

ok my program works the only thing i cant figure out how to do is, print the sum,

Maybe you can use cout <<"The sum of the numbers is : " << sum << endl; ;)

... average

Average is sum / #-of-values

ok i got the numbers to print out in reverse order but i can getthe sum and average to print out in reverse order. anyone got anything for me.

Sure. Since you are already outputting the sum, why can't you output the sum? And how do you print a sum and average in reverse order?


But to fix a couple things:

#include "stdafx.h";
#include <iostream>
#include <string>
using namespace std;

int numbers, sum, average;

int main()
{
    int numbers[5];
    double sum, average;
    int counter;
    cout <<"Enter five numbers: " << endl;
    sum = 0;
    for(counter = 0; counter < 5; counter++)
    {
        cin >> numbers[counter];
        sum = sum + numbers [counter];
        average = sum / 5;  // you can't calculate the average in the loop
                            // move this outside the loop
    }
    cout << endl;
    cout <<"The sum of the numbers is : " << sum << endl;
    cout <<"The average of the numbers is: " << average;
    cout << endl;
    cout <<" "<< endl;
    cout <<"The numbers you have entered reverse order: " << endl;

// Use a loop here, like your input
    cout << numbers[4] << endl;
    cout << numbers[3] << endl;
    cout << numbers[2] << endl;
    cout << numbers[1] << endl;
    cout << numbers[0] << endl;
// end of loop
    cout <<" "<< endl;

    return 0;
}

no i got it to print the sum out, now i need to know how to printt the sum out backwards. example if the sum = 23 i need tot know how to make it print out 32 which would be the reverse order. if u run my program u will see what i mean.

no i got it to print the sum out, now i need to know how to printt the sum out backwards. example if the sum = 23 i need tot know how to make it print out 32 which would be the reverse order. if u run my program u will see what i mean.

Please use full English, not webspeak. Many people here come from non-English speaking countries and it's easier to read real words.

Look into the modulus (%) operator. That will give you each digit starting in reverse order.

ok i am new to programing what does that mean? (Look into the modulus (%) operator. That will give you each digit starting in reverse order.)

ok reverse order is flipping the numbers around. so if the sum was 12, the reverse sum would be 21. do you seewhat i am talking about.

this is what i am trying to do bellow but in my owen code, and i cant get it to work.

// arrays/reverse-input.cpp - Reverses order of numbers in input.#include <iostream>using namespace std;int main() {    //--- Declare array and number of elements in it.    float a[100000];    int n;   // Number of values currenlty in array.       //--- Read numbers into an array    n = 0;    while (cin >> a[n]) {        n++;    }       //--- Print array in reverse order    for (int i=n-1; i>=0; i--) {        cout << a[i] << endl;    }       return 0;}//end main

this is what i ment if u are looking at the post before this one.

/* arrays/reverse-input.cpp - Reverses order of numbers in input.
#include "stdafx.h";
#include <iostream>
#include <string>
using namespace std;
a = numbers
n = counter
int main() {
    //--- Declare array and number of elements in it.
    float a[100000];
    int n;   // Number of values currenlty in array.
   
    //--- Read numbers into an array
    n = 0;
    while (cin >> a[n]) {
        n++;
    }
   
    //--- Print array in reverse order
    for (int i=counter-1; i>=0; i--) 
 {
        cout << numbers[i] << endl;
    }
   
    return 0;
}//end main

Let's just pretend I didn't see your second example... :rolleyes:

Your first example works when spaced out properly, so now all you need to do is code in the average and sum, and then you're done.

ok i am new to programing what does that mean? (Look into the modulus (%) operator. That will give you each digit starting in reverse order.)

Open your book. Last few pages are an index. Look there.

If you're no using a book (for shame!), ever heard of GOOGLE?

It doesn't matter how new you are. You still have to look stuff up somewhere. :rolleyes:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.