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. - #include <iostream>
-
#include <iomanip>
-
#include <fstream>
-
-
using namespace std;
-
-
// Global const
-
-
-
// prototype
-
-
-
int main ()
-
{
-
// Varialbes, Arrays
-
const int CREDITS = 4;
-
int hours[CREDITS];
-
char letterGrade[CREDITS];
-
char lName[24],fName[24];
-
double totalPoint = 0;
-
int totalH = 0,totalG = 0,totalP1;
-
-
-
-
// fixed point
-
//cout << fixed << showpoint << setprecision(1) << endl;
-
-
// Message display to get student input
-
cout << " This Program will Calculate a Students \n";
-
cout << " Total Hours, Total Points, and Overall GPS \n";
-
cout << endl;
-
-
// Studendts Last Name
-
cout << " Enter The Students Last Name: ";
-
cin >> lName;
-
cout << endl;
-
-
// Students First name
-
cout << " Enter The Students Fisrt Name: ";
-
cin >> fName;
-
cout << endl;
-
-
// Students Credit Hours for Each Class
-
for (int index = 0;index < CREDITS;index++)
-
{
-
-
cout << " Enter The Credit Hour for Class " << (index + 1) << ": ";
-
cin >> hours[index];
-
totalH += hours[index]; // Figure total Credit Hours
-
while (hours[index] > 5 || hours[index] < 1)
-
{
-
cout << " !! That is an invalid Credit hour, please enter a valid Credit Hour !! \n";
-
cout << " Enter The Credit Hour for Class " << (index + 1) << ": ";
-
cin >> hours[index];
-
}
-
-
}
-
cout << endl;
-
-
// Students Letter Grade for Each Class
-
for (int index = 0;index < CREDITS;index++)
-
{
-
cout << " Please Enter A,B,C,D, or F for Each Class \n";
-
-
{
-
cout << endl;
-
cout << " Enter the Letter Grade for Class " << (index + 1) << ": ";
-
cin >> letterGrade[index];
-
cout << endl;
-
while (letterGrade[index] < 65 || letterGrade[index] > 70)
-
{
-
cout << " !! That is an invalid grade letter, please enter a valid grade letter !! \n";
-
cout << endl;
-
cout << " Enter the Letter Grade for Class " << (index + 1) << ": ";
-
cin >> letterGrade[index];
-
}
-
}
-
}
-
-
// Figure total points
-
-
-
//
-
-
-
cout << endl;
-
// Main Display Output
-
cout << " ____________________________________________\n";
-
cout << "| |\n";
-
cout << "| Danvilee Area Community College |\n";
-
cout << "|____________________________________________|\n",
-
cout << endl;
-
-
cout << " Student: " << lName << ", " << fName << endl;
-
cout << endl;
-
cout << " CLASS " << setw(17) << " CREDITS " << setw(10) << " GRADE \n";
-
cout << "____________________________________\n";
-
for (int index = 0;index < CREDITS;index++)
-
{
-
cout << endl;
-
cout << " Class " << (index + 1) << ": " << setw(10) << hours[index] << setw(10) << letterGrade[index] << endl;
-
cout << "____________________________________\n";
-
}
-
-
cout << endl;
-
-
// Letter Point Conversion
-
cout << endl;
-
-
-
cout << endl;
-
cout << " Total Credit Hours " << totalH << endl;
-
cout << endl;
-
-
for (int index = 0;index < CREDITS;index++)
-
{
-
totalG += letterGrade[index];
-
}
-
-
cout << endl;
-
-
// Total Point Value
-
for (int index = 0;index < CREDITS;index++)
-
{
-
double totalP = 0;
-
switch(letterGrade[index])
-
{
-
case 'A': letterGrade[index] = 4;
-
break;
-
case 'B': letterGrade[index] = 3;
-
break;
-
case 'C': letterGrade[index] = 2;
-
break;
-
case 'D': letterGrade[index] = 1;
-
break;
-
case 'F': letterGrade[index] = 0;
-
break;
-
}
-
}
-
-
// sum of calculations
-
int totalP = 0;
-
for (int index = 0;index < CREDITS;index++)
-
{
-
totalP = letterGrade[index] * hours[index];
-
cout << " Total Points " << totalP << endl;
-
}
-
-
-
-
cout << endl;
-
system("pause");
-
return 0;
-
}
-
-
// fucntions
1 3165
I may not understand your problem exactly but this code will display totals in a column: - // sum of calculations
-
int totalP = 0;
-
for (int index = 0;index < CREDITS;index++)
-
{
-
totalP = letterGrade[index] * hours[index];
-
cout << " Total Points " << totalP << endl;
-
}
-
Also, there is no display of totalP after the loop completes so all you are getting is row totals.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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...
| |