Hi,
I'm working on a program that takes the following input from the user:
Student Name, Student Number, and Student GPA
The information is then supposed to be stored in three separate arrays.
Prior to sending the output to the screen, a bubble sort has to be performed
so that it's sorted by Student Name.
Here is the code I have so far, but I'm having the following problems:
1 - I'm unsure about the first while loop for input (need to know what I
should be comparing it to, so that it breaks properly.
2 - I need to know more about the sorting of parallel arrays -
int studentNumber[50];
-
string studentName[50],temp;
-
double studentGPA[50],temper;
-
int i=0,tmp;
-
int x = 0;
-
int y = 0;
-
int ia = 0;
-
int length = 0;
-
-
/* Prompt user for input of studentNumber, studentName, and studentGPA */
-
while (studentNumber[i] != 0)
-
{
-
-
-
cout << "Enter Student Number: ";
-
cin >> studentNumber[i];
-
cout << endl;
-
cout << "Enter Student Name: ";
-
cin >> studentName[i];
-
cout << endl;
-
cout << "Enter Student GPA: :";
-
cin >> studentGPA[i];
-
cout << endl;
-
i = i + 1;
-
}
Any help is greatly appreciated. I know that it's probably something simple, but my eyes having been looking at the code all afternoon and I'm missing something.
Earl
8 5263 Ganon11 3,652
Recognized Expert Specialist
For the while loop, why not add a char variable before the loop initialized to 'Y'. Inside the loop, ask the user, "Do you want to enter more data?" and input into the character. Then your loop condition will be "Continue while the character is 'Y' or 'y'".
For sorting the parallel arrays, it looks like you have the right idea.
For the while loop, why not add a char variable before the loop initialized to 'Y'. Inside the loop, ask the user, "Do you want to enter more data?" and input into the character. Then your loop condition will be "Continue while the character is 'Y' or 'y'".
For sorting the parallel arrays, it looks like you have the right idea.
Many thanks for your help...
I have the while loop working great :)
However, my sort doesn't appear to be working....
Any ideas?
Earl
Many thanks for your help...
I have the while loop working great :)
However, my sort doesn't appear to be working....
Any ideas?
Earl
Well, I did manage to fix the sorting code, but the output to the screen has
something funky going on. If anyone can figure it out, I would be greatful.
Data:
123456 Bakter 3.0
342130 Carson 3.8
111230 King 4.0
234512 Zimmerman 3.1
Output Display: ![](/images/imgserve.php?url=http://www.turnkeygold.com/images/display.jpg) Ganon11 3,652
Recognized Expert Specialist
Very strange...Where are you outputting the data? Can we see just that portion of the code again?
It looks like it is trying to output garbage data, like memory addresses or something.
DeMan 1,806
Top Contributor
I think there may be a slight problem with -
while(studentNumber[i] != 0)
-
{
-
cin >> studentNumber[i];
-
-
// other things
-
i = i + 1;
-
}
-
This means you are comparing to an unitialised array value......(I think this may be why Ganon11 suggested adding a "do you want to do more" type statement on the while loop)
I want to thank everyone for their great help :)
I did solve the mystery data output problem that was in my screenshot
earlier.
It was a result of not subtracting '1' from my inner loop counter when
the 'done' condition was met.
The mystery data that you seen on the screen was the contents
of the next array, which hadn't been filled yet :)
Earl
Ganon11 3,652
Recognized Expert Specialist
It's always something simple :)
Good to see you figured it out!
I just had to take it section, by section and walk through the logic with some
debugging prints to the screen.
It sure feels good to solve those problems and see the software do exactly what you want it too :)
Earl
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John |
last post by:
Hi all,
I've got an issue with session variables in asp pages. I need to make a
decision that I think you can hopefully help me out here.
When a session starts on the iss server I need to store some information in
some session variables. But this information is coming from an old dbase
system. In the beginning of this project it was just a simple static array
of information. Afterwards it turns out that this must be a dynamic array...
|
by: Till Crueger |
last post by:
Hi,
I have to implement some simple sorting algorithm. I am NOT asking for you
to do my homework, but my question is rather on how to store the integers.
I recall reading once in here that there is a maximum value the operator
has to accept. Since the programm should accept almost any number of
integers, I am not sure if this limit will be enough.
Also I would like to know the same about the STL-Vector class, since I
haven't decided...
|
by: Xiaozhu |
last post by:
say, if you had parallel arrays containing the sales person id, the month, and
the sales figures (for that person in that month), sorting on sales figure and
preserve the order of figures within the data about the same person:
Original Data:
id month sales
+-----+ +-----+ +-----+
| 432 | | 8 | | 89 |
+-----+ +-----+ +-----+
| 123 | | 8 | | 116 |
|
by: Jack |
last post by:
hi all
I would find a parallel sorting algorithms written with pthread
programs, as a benchmark to run.
Any pointing will be of help
thankyou in advance
|
by: yatindran |
last post by:
hai
this is my 2d array.
int a = {
{5,2,20,1,30,10},
{23,15,7,9,11,3},
{40,50,34,24,14,4},
{9,10,11,12,13,14},
{31,4,18,8,27,17},
{44,32,13,19,41,19},
{1,2,3,4,5,6},
| |
by: ssg31415926 |
last post by:
I need to compare two string arrays defined as string such that the
two arrays are equal if the contents of the two are the same, where
order doesn't matter and every element must be unique.
E.g. these two arrays would test as equal:
servers = "Admin"
servers = "Finance"
servers = "Payroll"
servers = "Sales"
|
by: kmuz08 |
last post by:
Hello to everyone,
I have to do a project in my discovering programming class based on creating parallel arrays for an order form. I am still not completely sure was a parallel array is! But basically any help, tips, pr tricks would help. My program is to allow the user to enter the name of a product, the product number or serial number, the quantity, and the cost per item and have them all displayed in different parrallel...
|
by: SneakyElf |
last post by:
i am very green with c++ so i get stuck on very simple things
anyway, i need to write a program that would
read data from file (containing names of tv shows and their networks)
one line at a time ( ; separates tv show and network)
sort the strings according to the network and according to the show.
and so:
//to open file -
ifstream myFile;
|
by: mh |
last post by:
I want to interate over two arrays in parallel, something like this:
a=
b=
for i,j in a,b:
print i,j
where i,j would be 1,4, 2,5, 3,6 etc.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |