I need help with two parallel arrays

This is a discussion on I need help with two parallel arrays within the C++ Programming forums, part of the General Programming Boards category; I'm suppose to write a program that uses two parallel arrays to store student names and their grades. It should ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    5

    I need help with two parallel arrays

    I'm suppose to write a program that uses two parallel arrays to store student names and their grades. It should use an array of strings that hold the names and and array of integers that hold the grades. The program should produce a report that displays list of students names and grades, and the name of the student that has the highest grade. The names and grades should be stored using an initialization list at the time the arrays are created. Use a loop and conditional statement to determine which student has the highest grade.

    This is what I have tried so far. I'm new at this and there not many good examples in the book


    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    #include <string>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int i = 0, h = 0, saved = 0;
    
    	int g[ ] = {87, 99, 70, 75, 77, 91, 95};
    	string s [ ]= {"S1", "S2", "S3", "S4", "S5", "S6", "S7"};
    
    	while ( i <= 3)
    	{if (g[i] > h)
    	{h = g[i];
    	  saved = i;
    	}
    	}
    	cout << "Highest " << h;
    	cout << "student is " << s[saved];
    
    	return 0;

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > while ( i <= 3)
    You need a for loop, to examine each element of the array.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Code:
    while ( i <= 3)
    where do you get this 3 stuff?

    in general loop for all array members will look like

    Code:
    for(i=0; i < sizeof(g)/sizeof(g[0]); i++)
    {
    }
    after that - your finding highest score alg should work fine

    and what left - is to use another loop to print all students (or even the same loop)
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  2. Parallel Arrays
    By kippwinger in forum C++ Programming
    Replies: 3
    Last Post: 06-26-2003, 03:18 PM
  3. Parallel Arrays-HELP!
    By ProgrammingDlux in forum C++ Programming
    Replies: 3
    Last Post: 03-28-2002, 02:55 PM
  4. Parallel Arrays with Multiple Arrays
    By Billye Scott in forum C++ Programming
    Replies: 0
    Last Post: 03-02-2002, 10:14 PM
  5. parallel arrays
    By KeeNCPP in forum C++ Programming
    Replies: 1
    Last Post: 10-18-2001, 09:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21