473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Summing two Parallel Arrays to display the sum of both arrays

I am having a problem with my program to calculate the GPA of a student. The problem that I am having is that I am not able to get my Total Point Value to display the sum of the two arrays. The multiplication for the array is correct and will display correctly, but instead of putting the total into the accumulator it will display the totals in a column. I have tried moving the coding for the calculation out of the loop that converts the letter grade into a point value,and placing it in it's own loop, but I still get the same display output. Any hints as to what I am doing wrong or what I need to do would be great. below is the code that I have so far. I still have a few elements to add to the code, but they will be easy once I get this display to work right.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. // Global const
  8.  
  9.  
  10. // prototype
  11.  
  12.  
  13. int main ()
  14. {    
  15. // Varialbes, Arrays
  16.     const int CREDITS = 4;
  17.     int hours[CREDITS];
  18.     char letterGrade[CREDITS];
  19.     char lName[24],fName[24];
  20.     double totalPoint = 0;
  21.     int totalH = 0,totalG = 0,totalP1;
  22.  
  23.  
  24.  
  25. // fixed point
  26.     //cout << fixed << showpoint << setprecision(1) << endl;
  27.  
  28. // Message display to get student input
  29.     cout << " This Program will Calculate a Students \n";
  30.     cout << " Total Hours, Total Points, and Overall GPS \n";
  31.     cout << endl;
  32.  
  33. // Studendts Last Name 
  34.     cout << " Enter The Students Last Name: ";
  35.         cin >> lName;
  36.     cout << endl;
  37.  
  38. // Students First name
  39.     cout << " Enter The Students Fisrt Name: ";
  40.         cin >> fName;
  41.     cout << endl;
  42.  
  43. // Students Credit Hours for Each Class
  44.     for (int index = 0;index < CREDITS;index++)
  45.     {
  46.  
  47.             cout << " Enter The Credit Hour for Class " << (index + 1) << ": ";
  48.             cin >> hours[index];
  49.             totalH += hours[index]; // Figure total Credit Hours
  50.         while (hours[index] > 5 || hours[index] < 1)
  51.         {
  52.             cout << " !! That is an invalid Credit hour, please enter a valid Credit Hour !! \n";
  53.             cout << " Enter The Credit Hour for Class " << (index + 1) << ": ";
  54.             cin >> hours[index];
  55.         }        
  56.  
  57.     }
  58.     cout << endl;
  59.  
  60. // Students Letter Grade for Each Class
  61.     for (int index = 0;index < CREDITS;index++)
  62.     {
  63.         cout << " Please Enter A,B,C,D, or F for Each Class \n";
  64.  
  65.         {
  66.             cout << endl;
  67.             cout << " Enter the Letter Grade for Class " << (index + 1) << ": ";
  68.                 cin >> letterGrade[index];
  69.             cout << endl;
  70.             while (letterGrade[index] < 65 || letterGrade[index] > 70)
  71.             {
  72.                 cout << " !! That is an invalid grade letter, please enter a valid grade letter !! \n";
  73.                 cout << endl;
  74.                 cout << " Enter the Letter Grade for Class " << (index + 1) << ": ";
  75.                     cin >> letterGrade[index];
  76.             }
  77.         }
  78.     }
  79.  
  80. // Figure total points
  81.  
  82.  
  83. // 
  84.  
  85.  
  86.     cout << endl;
  87. // Main Display Output
  88.     cout << " ____________________________________________\n";
  89.     cout << "|                                            |\n";
  90.     cout << "|     Danvilee Area Community College        |\n";
  91.     cout << "|____________________________________________|\n",
  92.     cout << endl;
  93.  
  94.     cout << " Student: " << lName << ", " << fName << endl;
  95.     cout << endl;
  96.     cout << " CLASS " << setw(17) << " CREDITS " << setw(10) << " GRADE \n";
  97.     cout << "____________________________________\n";
  98.     for (int index = 0;index < CREDITS;index++)
  99.     {
  100.         cout << endl;
  101.         cout << " Class " << (index + 1) << ": " << setw(10) << hours[index] << setw(10) << letterGrade[index] << endl;
  102.         cout << "____________________________________\n";
  103.     }
  104.  
  105.     cout << endl;
  106.  
  107. // Letter Point Conversion
  108.     cout << endl;
  109.  
  110.  
  111.     cout << endl;
  112.     cout << " Total Credit Hours " << totalH << endl;
  113.     cout << endl;
  114.  
  115.     for (int index = 0;index < CREDITS;index++)
  116.     {
  117.         totalG += letterGrade[index];
  118.     }
  119.  
  120.     cout << endl;
  121.  
  122. // Total Point Value
  123.     for (int index = 0;index < CREDITS;index++)
  124.     {
  125.         double totalP = 0;
  126.         switch(letterGrade[index])
  127.         {
  128.             case 'A': letterGrade[index] = 4;
  129.                 break;
  130.             case 'B': letterGrade[index] = 3;
  131.                 break;
  132.             case 'C': letterGrade[index] = 2;
  133.                 break;
  134.             case 'D': letterGrade[index] = 1;
  135.                 break;
  136.             case 'F': letterGrade[index] = 0;
  137.                 break;
  138.         }
  139.     }
  140.  
  141. // sum of calculations
  142.     int totalP = 0;
  143.     for (int index = 0;index < CREDITS;index++)
  144.     {
  145.         totalP = letterGrade[index] * hours[index];
  146.         cout << " Total Points " << totalP << endl;
  147.     }
  148.  
  149.  
  150.  
  151.     cout << endl;
  152.     system("pause");
  153.     return 0;
  154. }
  155.  
  156. // fucntions
Aug 17 '13 #1
1 3165
weaknessforcats
9,208 Expert Mod 8TB
I may not understand your problem exactly but this code will display totals in a column:

Expand|Select|Wrap|Line Numbers
  1. // sum of calculations
  2.     int totalP = 0;
  3.     for (int index = 0;index < CREDITS;index++)
  4.     {
  5.         totalP = letterGrade[index] * hours[index];
  6.         cout << " Total Points " << totalP << endl;
  7.     }
  8.  
Also, there is no display of totalP after the loop completes so all you are getting is row totals.
Aug 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
3
by: Bill Reyn | last post by:
I am a Java programmer, a newbie with c++, struggling a bit... Why does the code below return the starting address for an integer array, but for a char array it does not return the starting...
2
by: Nikhil Patel | last post by:
Hi all, I am readin an MSDN tutorial on C# arrays. It says, you can have a three-dimensional rectangular array: int buttons = new int; What I don't understand is how can a three dimensional...
2
by: nitin8or | last post by:
Hi ALL, I want to display in a RichTextBox the Binary Large Objects data coming from database. If I have one record its not a problem I convert it to byte array and pass it on in a stream as a...
6
by: Tau | last post by:
look my simple code below(vc8): double ends; ends=8.3; when i debug it, the variable ends cannot be displayed in the watch window. it just said "error: index '0' out of bound for...
9
by: barmy_mad | last post by:
Hi I new to C# and trying to store/extract a collection of multidimensional arrays. For example; string a_DATA = new string object o_CON = new object for(int i=0;i<10;i++){ for(int...
0
by: shotokan99 | last post by:
i have this issue: showpic.php ================================================ $ch = curl_init(); $timeout = 0; curl_setopt ($ch, CURLOPT_URL, $xmyurl); curl_setopt ($ch,...
6
by: aliasDyego | last post by:
Hi all, I am trying to display both text and image fields from MySQL in PHP page but unfortunately it doesn't work. Here is the code i used: $id = $_GET; $sql = "SELECT * FROM user,...
6
by: msmjsuarez | last post by:
how can i display both image and other information in the web page using php? i'm using mysql database. I do displaying the image only but i want to display both other information from the database...
0
by: Stacey Prahl | last post by:
Option Strict On Public Class frmBookPublishing ' Class Level Private Variables Private Shared _intSizeOfArray As Integer = 16 Private Shared _strWarehouseItem(_intSizeOfArray) As String...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.