How do I save the input form the user into an array?

Here is my assignment:
create a program that reads in 5 numbers, find their sum and then print them in reverse. Use array as a tool in your program.

Here is what I have so far:

#include <iostream>
#include <stdlib.h>
using namespace std;

// This program reads in five numbers, find their sum, then prints the numbers in reverse.//


int main ()
{




    const int numlist = 2;
    int num[ numlist];
    int total ;
    int numcount;








    for (numcount = 0; numcount < 2; numcount ++)

{

    cout << " Enter five numbers: " << endl;
    cin >>  num[2];
    cout << num[2];
}

    for ( int i =0; i< numlist; i++)
        total = num[i];

    cout << "\nThe total of the numbers are: " <<total  << endl;

    return 0;
}
#include <iostream>
// #include <stdlib.h> // You dont need this
using namespace std;

// This program reads in five numbers, find their sum, then prints the numbers in reverse.//
int main ()
{
	const int numlist = 5;
	int num[ numlist];
	int total = 0 ; // Remember to initialize variables
	int numcount; 
	for (numcount = 0; numcount < numlist; numcount++)
	{
		cout << "Enter number " << numcount << ": ";
		cin >> num[numcount];
	}
	for ( int i =0; i< numlist; i++)
	{
		total = total + num[i];
	}
	cout << "\nThe total of the numbers are: " <<total << endl;
	// To Print the numbers in reverse
	for ( int i =numlist - 1 ; i>=0; i--)
	{
		cout << num[ i ] << endl;
	}
	
	return 0;
}

Hello Wolfpack,

thank you for responding so promptly. I editted the code but I am still having some problems executing it. I keep getting an error message:

Array.cpp
C:\Documents and Settings\Administrator\My Documents\Array.cpp(26) : error C2374: 'i' : redefinition; multiple initialization
C:\Documents and Settings\Administrator\My Documents\Array.cpp(19) : see declaration of 'i'
Error executing cl.exe.

Array.obj - 1 error(s), 0 warning(s)

******************************************

Can you tell me what it means?

Akisha

#include <iostream>
// #include <stdlib.h> // You dont need this
using namespace std;

// This program reads in five numbers, find their sum, then prints the numbers in reverse.//
int main ()
{
	const int numlist = 5;
	int num[ numlist];
	int total = 0 ; // Remember to initialize variables
	int numcount; 
	for (numcount = 0; numcount < numlist; numcount++)
	{
		cout << "Enter number " << numcount << ": ";
		cin >> num[numcount];
	}
	for ( int i =0; i< numlist; i++)
	{
		total = total + num[i];
	}
	cout << "\nThe total of the numbers are: " <<total << endl;
	// To Print the numbers in reverse
	for ( int i =numlist - 1 ; i>=0; i--)
	{
		cout << num[ i ] << endl;
	}
	
	return 0;
}

Edit this

for ( int i =numlist - 1 ; i>=0; i--)
{
	cout << num[ i ] << endl;
}

to this

for ( i =numlist - 1 ; i>=0; i--)
{
	cout << num[ i ] << endl;
}

Disregard the last thread. I figured it out.

use STL instead, this is a job for vector.
Stroustrup himself advises against using arrays whereever STL can be used instead.

can you help with this program?

#include <iostream>

using namespace std;


// This program takes the numerical score and outputs a letter grade.//

int getScore ()
{


    int count;
    int score;

    for (count = 0; count <1; count ++){
    cout << "\nEnter the student's score: "<< endl;
    cin >> score;

    }


    cout <<"\nThe score is/are: " << score << endl;
    return 0 ;
}




int printGrade()

{
    int grade =0;
    int count;




    for (count = 0; count <1; count ++){ 


    switch(grade)
{
   case 90:
        cout << "\nYour grade is A.\n" << endl;
      break;
   case 80:
        cout << "\nYour grade is B.\n" << endl;
    break;
   case 70:
       cout << "\nYour grade is C.\n" << endl;
       break;
    case 60:
       cout << "\nYour grade is D.\n" << endl;
       break;
    case 50:
       cout << "\nYour grade is F.\n" << endl;

    }
    }


return 0;

}

int main ()
{

    getScore ();
    printGrade();













 return 0;
}

I'm stuck again. Your asistance is greatly appreciated.

#include <iostream>

using namespace std;


// This program takes the numerical score and outputs a letter grade.//

int getScore ()
{


    int count;
    int score;

    for (count = 0; count <1; count ++){
    cout << "\nEnter the student's score: "<< endl;
    cin >> score;

    }


    cout <<"\nThe score is/are: " << score << endl;
    return 0 ;
}




int printGrade()

{
    int grade =0;
    int count;




    for (count = 0; count <1; count ++){ 


    switch(grade)
{
   case 90:
        cout << "\nYour grade is A.\n" << endl;
      break;
   case 80:
        cout << "\nYour grade is B.\n" << endl;
    break;
   case 70:
       cout << "\nYour grade is C.\n" << endl;
       break;
    case 60:
       cout << "\nYour grade is D.\n" << endl;
       break;
    case 50:
       cout << "\nYour grade is F.\n" << endl;

    }
    }


return 0;

}

int main ()
{

    getScore ();
    printGrade();













 return 0;
}
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.