Parallel Arrays in C++

Published on: October 24, 2010

In this tutorial, I show you more about using Arrays in C++. In the last tutorial, I've shown you some very basics of how arrays work, here I show you how to work with Parallel Arrays, also known as multiple arrays. Here You calculate and output results very easily.

Arrays are very helpful. This tutorial only handle single dimensional arrays but deals with multiple array variables as well as implement the 'for' loop for more practice.

I hope you enjoy the video and if you have any requests feel free to let me know. Thanks for watching ! Thanks for watching and thanks for your supportand remember to subscribe!

Remember to checkout the Codesnip below to review the C++ code yourself! Feel free to copy the code, but I ask that you please provide credit if you leave the code unchanged when you use it.

Codesnip:

//Programmer: Nazmus
//Website:  EasyProgramming.net
//Program:  Array Tutorial #2 - Parallel Arrays

#include <iostream>
#include <string>

using namespace std;
int main(){

 string name[3];
 int test1[3];
 int test2[3];
 float avg[3];
 int i;

 for(i=0;i<=2;i++){

  cout << "Please enter student's name: ";
  cin >> name[i];

  cout << "Please enter first test score: ";
  cin >> test1[i];

  cout << "Please enter second test score: ";
  cin >> test2[i];
 }

 for(i=0;i<=2;i++){
  avg[i] = (test1[i] + test2[i]) / 2;
 }

 cout << endl;

 cout << "Name" << "          " << "Average" << endl;

 for(i=0;i<=2;i++){
  cout << name[i] << "          " << avg[i] << endl;
 } 

 system("pause");
}



Comments: