C++, an if loop for an assignment - c++

I need some help trying to figure out a way to make an if statement taking the users input after a category is typed in. If the user types in string categories[0] in the cin statement, which in this case is "Number of drivers involved in fatal collisions per billion miles." I want it to display the first sentence from the worststate[0] array, which in this case will be North Dakota and South Carolina. I need help doing that for every category, to match up with the state listed, it goes in order.
#include <iostream>
using namespace std;
string worstState[7] = {
{"North Dakota and South Carolina"},
{"Hawaii"},
{"Montana"},
{"District of Columbia"},
{"District of Columbia and Mississippi"},
{"New Jersey"},
{"Louisiana"},
};
void displayIntro(){
cout << "Welcome to the Car Accident Statistic Website" << endl;
cout << "Take a look at the following categories: " << endl;
}
string categories[7] = {
{"Number of drivers involved in fatal collisions per billion miles"},
{"Percentage of drivers involved in fatal collisions who were speeding"},
{"Percentage of drivers involved in fatal collisions who were Alcohol-Impaired"},
{"Percentage of drivers involved in fatal collisions who were not distracted"},
{"Percentage of drivers involved in fatal collisions who had not been involved in any previous accidents"},
{"Car Insurance Premiums"},
{"Losses incurred by insurance companies for collisions per insured driver"},
};
int main(){
string Input;
displayIntro();
cout << categories[0] << endl;
cout << categories[1] << endl;
cout << categories[2] << endl;
cout << categories[3] << endl;
cout << categories[4] << endl;
cout << categories[5] << endl;
cout << categories[6] << endl;
cout << "Enter a category: ";
cin >> Input;
if (Input == categories....
return 0;
}
Obviously the code isn't the best organized, which I'm still gonna work on, but I just want the user to type in the category string, and for the state to match up with that specific category in the categories array, all in order based on the way they are entered.
Wondering what the best way to go about this situation is

You can use an unordered_map (aka hash table):
Initialize the map at the start of your program that maps all the questions to their respective answers (i.e. categories[i] to worstState[i]).
unordered_map<string, string> questionsToAnswers;
for (size_t i = 0; i < 7; i++) {
questionsToAnswers[categories[i]] = worstState[i];
}
When the user types a string in, you can look up the answer like this:
string s;
cin >> s;
auto itor = questionsToAnsers.find(s);
if (itor != questionsToAnswers.end()) {
cout << itor->second;
} else {
// question not found in map
}

If I understand correctly if the user inputs in categories[0], you want to display worstState[0], if the user inputs in catergories[1], you want to display worstState[1], and so on. Now it looks like your input is fixed which means you can use a switch statement, however because there are a fairly large number of courses you want to consider a for loop probably would look more clean.
So something like:
for(int i = 0; i < size(categories); i++){
if(Input == categories[i]){
cout << worstState[i] << endl;
}
}

Related

Transversing an Array of structs error in C++

Current code:
const int MAX_CODENAME = 25;
const int MAX_SPOTS = 5;
struct Team {
string TeamName[MAX_CODENAME];
short int totalLeagueGames;
short int leagueWins;
short int leagueLoses;
};
//GLOBAL VARIABLES:
Team league[MAX_SPOTS];
void addTeams(){
int i = 0; //first loop
int j; //second loop
while(i < MAX_SPOTS){
cout << "****** ADD TEAMS ******" << endl;
cout << "Enter the teams name " << endl;
scanf("%s", league[i].TeamName) ;
}
void searchTeam(){
string decider[MAX_CODENAME];
cout << "Please enter the team name you would like the program to retrieve: " << endl;
cin >> decider[MAX_CODENAME];
for(int i = 0; i < MAX_SPOTS; i++){
if(decider == league[i].TeamName){
cout << endl;
cout << league[i].TeamName << endl;
break;
}else{
cout << "Searching...." << endl;
}
}
}
I really dont know why its not working but I have included all the perquisite header files such as and but the program crashes when i enter the data and then attempt to search. I get the circle of death and then program not responding then says Process returned 255 (0xFF) . It does not even out put Searching.... the program practically gives up as soon as I enter that name.
Also if this can be optimized by the use of pointers that would be great.
tl;dr run-time error causing the search to fail as soon as i type in a name. And for the record I have checked to make sure the name I entered is valid.
scanf doesn't know about std::string. Use std::cin >> league[i].TeamName.
scanf("%s", league[i].TeamName) ;
This should be changed to
std::cin >> league[i].TeamName ;
A couple of other things here....
string decider[MAX_CODENAME];
cout << "Please enter the team name you would like the program to retrieve: " << endl;
cin >> decider[MAX_CODENAME];
Every time you input a value, you are telling the computer to hold the inputted value at decider[25] but the computer only reads indexes 0-24.
if(decider == league[i].TeamName){
Which array slot are you comparing the team name to? If its the 25th element than the statement should be
if(decider[24] == league[i].TeamName){
Pointers are better suited if the number of TeamNames are unknown. Based on the limited code presented, I highly recommend you stay within the realm of basic data types. For the purposes of troubleshooting, please post your full code in the future.
Your TeamName member variable:
string TeamName[MAX_CODENAME];
is an array of 25 strings, so in this line:
scanf("%s", league[i].TeamName) ;
you are courrupting the array. You don't really want an array anyways, so change the TeamName declaration to:
string TeamName;
and then when you read the name, you'll need to use iostreams which knows how to populate a string type (scanf only works with c char arrays):
std::cin >> league[i].TeamName

C++ Array not taking correct input from file

Disclaimer: I am a beginner to programming, so what I say might sound really stupid
I have to make a "Telephone Directory" for school. The program isn't complete, but there are some things that I need to fix before moving on. The array TelephoneNumbers either isn't storing the numbers from the file correctly, or isn't displaying them. For the SeaerchRecords function, the first number in the file is displayed correctly, the second is displayed as "2147483647," and the rest of the numbers display as "0." The modify function also doesn't change the number, and I confirmed this with the while in the function. The string array works perfectly fine, however. May someone explain what I'm doing incorrectly?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string TelephoneNames[100];
int TelephoneNumbers[100];
void ModifyRecords(); //Function to Modify Records
void SearchRecords(); //Function to Search Records
void DeleteRecords(); //Function to Delete Records
int main()
{
fstream inputFile;
fstream outputFile;
char choice;
inputFile.open("Telephone Names.txt"); //To store
for (int count=0;count<100;count++) //file names
{ //into a
inputFile >> TelephoneNames[count]; //string
}
inputFile.close();
inputFile.open("Telephone Numbers.txt");//To store
for (int count=0;count<100;count++) //file #'s
{ //into a
inputFile >> TelephoneNumbers[count];//string
}
inputFile.close();
//Display options available
cout << " Hello, do you want to:\n";
cout << " ======================\n";
cout << "-Modify Records|Enter M\n";
cout << "-Search Records|Enter S\n";
cout << "-Delete Records|Enter D\n";
//Store choice
cin >> choice;
//Send to different function
if (choice=='M'||choice=='m')
{
ModifyRecords();
}
if (choice=='S'||choice=='s')
{
SearchRecords();
}
return 0;
}
void ModifyRecords()
{
string name;
string newname;
int newnumber;
int count=0;
cout << "Enter the name of the person: ";
cin >> name;
for (count=0;TelephoneNames[count]!=name;count++)//To determine where in the strings the new numbers need to be
{
}
cout << "Enter the new name of the person: ";
cin >> newname;
cout << "Enter the new number of the person: ";
cin >> newnumber;
TelephoneNames[count]={newname};
TelephoneNumbers[count]={newnumber};
count=0;
while (count<6)
{
cout << TelephoneNames[count] << endl;
cout << TelephoneNumbers[count] << endl;
cout << endl;
count++;
}
}
void SearchRecords()
{
string name;
int count=0;
cout << "Enter the name of the person you would like to find: ";
cin >> name;
for (count=0;TelephoneNames[count]!=name;count++)//To determine where in the strings the new numbers need to be
{
}
cout << "Name: " << TelephoneNames[count] << endl;
cout << "Number: " << TelephoneNumbers[count] << endl;
}
Since there is no any answer still and I don't see exactly the problem at this point I'll provide some suggestions how you can find a problem in your code.
In any programming situation when you can't find a bug, first task is to locate it as much precisely as you can and check all input data and assumptions. Usually, debugger is used for such purposes, but you can just output text in console before creating final version of your program.
To start with, you must check that you really received names and telephones from your file:
inputFile.open("Telephone Names.txt"); //To store
for (int count=0;count<100;count++) //file names
{ //into a
inputFile >> TelephoneNames[count]; //string
cout << TelephoneNames[count] << endl; //WE MUST SEE WHAT IS REALLY STORED IN TelephoneNames
}
inputFile.close();
inputFile.open("Telephone Numbers.txt");//To store
for (int count=0;count<100;count++) //file #'s
{ //into a
inputFile >> TelephoneNumbers[count];//string
cout << TelephoneNumbers[count] << endl; //WE MUST SEE WHAT IS REALLY STORED IN TelephoneNumbers
}
inputFile.close();
Ok, when it is checked and you are defenitely sure there is no problem in your data we can move to SeaerchRecords function doing the same procedure. We must check what is happening while you are searching:
for (count=0;TelephoneNames[count]!=name;count++)//To determine where in the strings the new numbers need to be
{
cout << "Search step: " << count << " name " << name << " found name " << TelephoneNames[count] << " number " << TelephoneNumbers[count] << endl;
}
Doing so you will locate your bug rather quickly. The problem can be in input files format, in difference of "name" and stored names format etc.
I'll provide several additional suggestion how you can improve your code.
1) Try to use const declarations for such commonly used things as number of records (const int NUMBER_OF_RECORDS = 100; insted of just putting '100' everywhere), it will reduce the amout of work and possible bugs. 2) Try to check all possible problems that you program can encounter if someting is wrong with data. What will happen if you have less than 100 records in your files now? Program crush or silent reading of unappropriate data which is even worse. Check that you haven't reach file end on any step of reading along with current check that you've reached you number of records and do something in case of unappropriate data.
3) Check the possible problems with conditions in your cycles not to run them infinite number of times. Now your condition for(count=0;TelephoneNames[count]!=name;count++)
will execute forever if there is no such name or just crush the program on count 100 or more. You should check that count doesn't exceed that value. Good luck!

Printing two vectors to screen in columns next to each other?

So, my program uses a while loop to fill two separate vectors by asking the name of an item (vector one) then asking the price of the item (vector two).
double ItemCost;
vector<double> Cost;
string ItemName;
vector<string> Item;
while (ItemName != "done")
{
cout << "Item name: "; cin >> ItemName;
Item.push_back(ItemName);// gets item name from use and stores in the vector "Item"
if (ItemName != "done")
{
cout << "Item cost: $"; cin >> ItemCost;
Cost.push_back(ItemCost);// gets cost of item and stores it in the vector "cost"
}
else
{
continue;
}
}
system("CLS");
So after the clear screen, I would like the program to output a screen that shows the item name, then to the right it's cost. Then on the next line the same thing for the 2nd item input. Essentially like this would display:
cout << Item[0]; cout << " $" << Cost[0];
cout << Item[1]; cout << " $" << Cost[1] << endl;
cout << Item[2]; cout << " $" << Cost[2] << endl;
But, I want it to do this no matter how many items are input, also doing it the way I did above is obviously a bad Idea if they input less then the amount I have in the code, because the program will try to reach outside the vectors occupied memory ect. That was just to give an example of the format I'm going for.
If the vectors are the same size, you can use a simple for loop to iterate over the contents:
for (int i = 0; i < Item.size(); ++i) {
cout << Item[i] << " $" << Cost[i] << endl;
}
Before you run this code, you might want to check the two vectors have the same size using a debug assertion:
assert(Item.size() == Cost.size();
Alternatively, you could use perhaps something like std::min to only loop up the the smallest of the two vectors in case they are different sizes.
I would suggest using a std::vector of std::pair to store the price and item together this is simply because it makes keeping track of which price is associated with which item. This removes the need to check that both vectors are the same size and minimizes the chance for an error to occur. Then it is a simple matter of using a range based for loop to iterate through each pair and print them. I have shown an example below with a few improvements. There are a number of advantages of using std::pair over a simple struct, one such advantage is the inclusion of the necessary Boolean functions to be used in something like std::sort() Which if used would essentially sort your list of items alphabetically. This is very useful if you want to future proof your code.
double ItemCost;
string ItemName;
vector<std::pair<string, double> > Item;
while (ItemName != "done")
{
cout << "Item name: ";
// Using std::getline() as it terminates the string at a newline.
std::getline(std::cin, ItemName);
if (ItemName != "done")
{
cout << "Item cost: $"; cin >> ItemCost;
Item.push_back(std::make_pair (ItemName,ItemCost));
}
else
{
continue;
}
}
system("CLS");
// Printing here using c++11 range based for loop, I use this extensively
// as it greatly simplifies the code.
for (auto const &i : Item)
{
std::cout << i.first << "\t\t$" << i.second;
// ^^ Using double tab for better alignment
// instead of spaces.
}
Vector knows how big it is so there are a bunch of simple solutions, the easiest being
for (size_t index = 0; index < Item.size() && index < Cost.size(); index++)
{
cout << Item[index]; cout << " $" << Cost[index] << endl;
}
But a better idea is to have one vector that stores something like
struct ItemCost
{
string name;
double cost; // but it's generally safer to store money by pennies in integers
// You can't always count on floating point numbers in comparisons
}
This way Item and Cost can never get out of synch.
Read here for more on why floating point fails for precise things like money: How dangerous is it to compare floating point values?

C++ file input/output and array assistance

I have a C++ project to do for my class and it's quite intricate, to me at least. I've got the general idea and concept down, but i'm running into some other problems when it comes to the arrays and file stuff. Below is what the project consists of
You will be building and modifying a class roster system for a Teacher to manage his class roster and their final grades. This program
will use functions for the various menu options, and you will work with
the data in arrays or vectors. The program will provide a menu system that allows for the teacher to perform tasks until he chooses to close the program. The program will read and write to a file called
classroster.txt. Any and all additions, deletions, or changes to the roster will be saved in classroster.txt file.
This file will contain the names of each of the students in the class with their grade. See the following for an example listed below of how the data would be stored in the classroster.txt file. You should work with the data using arrays or vectors.
Jim Jones C
Kevin James B
Marc Cohen A+
When the program starts it should read the data from the classroster.txt into arrays or vectors. While the program is running it should use the arrays or vectors for the functions while using the program. When the program ends it should overwrite the classroster.txt file if something has been changed. The
programs menu will offer the following options and will allow the user to keep performing functions until they choose to exit the program ( hint !!!!! you will need to use a loop for the menu system)
Add A New Student-
This will allow the user to add a new student to the system. The system should prompt for the new students full name and then grade.
It should validate that the grade is in the following values
(A+, A, A-, B+, B, B-,C+,C, C-, D+, D, D-, F) and if not
in the approved list it should prompt the user for a valid grade.
Change a Students Grade-
This will find the student in question and change the grade. If the specified student doesn’t exist the program should print an error message telling the user that you couldn’t find the specified student to
change their grade.
Remove a Student-
Will remove a student and their grade from the roster. If the specified student doesn’t exist the program should print an error message telling the user that you couldn’t find the specified student to remove.
Display Class Roster–
(Bonus Points if you can display the names is alphabetical order) This
function will display the list of all the students and their grades on
the screen that looks like this:
Student Name Grade
Jim Jones C
Kevin James B-
Marc Cohen A+
This is what i have so far, it's obviously not done yet
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
const int num_of_students;
const int new_student = 1, change_grade = 2, remove_student = 3, display_roster = 4, quit = 5;
int classroster[num_of_students];
int student_grade[num_of_students];
string possible_grades[13] = {"A+", "A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F"};
int choice;
ofstream class_file;
cout << "How many students do you have in your class?" << endl;
cin >> num_of_students;
cout << "---MENU---" << endl;
cout << "1. Add A New Student" << endl;
cout << "2. Change A Students Grade" << endl;
cout << "3. Remove A Student" << endl;
cout << "4. Display Class Roster" << endl;
cout << "5. Quit" << endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice == new_student) {
for (int index = 0; index < num_of_students; index++) {
class_file.open("classroster.txt");
cout << "What is the name of the student you want to add? ";
getline(cin, classroster);
if (student_grade == possible_grades) {
cout << "What is the final grade of this student? ";
getline(cin, student_grade);
}
else {
"Please enter a valid grade!"
}
cout << "Student added!";
}
}
else if (choice == change_grade) {
class_file.open("classroster.txt");
cout << "What is the name of the student whose grade you want to change? ";
getline(cin, )
}
else if (choice == remove_student) {
}
else if (choice == display_roster) {
}
else if (choice == quit) {
}
else {
cout << "Please enter a valid choice!"
}
system("PAUSE");
return 0;
}
First, to answer your question, here's one way to search an array of student names:
int index = -1;
for(int k=0; k<num_of_students; ++k)
{
if(names[k] == name)
index = k;
}
And here's a way to change the array of grades:
student_grade[index] = 3;
More generally, you taking the wrong approach. Your code does not compile, so it looks as if you're writing it all out before testing any of it. As they never seem to teach in school, you should start with something small and simple, add complexity a little at a time, test at every step, and never add to code that doesn't work.
Let's start with the number of students:
int main() {
const int num_of_students;
cout << "How many students do you have in your class?" << endl;
cin >> num_of_students;
return(0);
}
Try to compile this, and you'll find that there's something wrong. Fix it and try constructing an array of int and filling it in. Once that's working, try an array of string. Small steps.
You realy should be using maps for this question, its makes the most sense. Here is code to read in the map from a file. After you have the map all the operations you need are already implemented in the STL. I realize you may need to use vector but I'd like to think you wouldn't be penalized for being clever and actually writing a proper solution.
#include <map>
#include <fstream>
#include <iostream>
using namespace std;
int main(){
map<string,string> data;
fstream fs("classroster.txt");
while(fs.good()){
string fname, lname, grade;
fs >> fname;
fs >> lname
fs >> grade;
fname += lname; //Concat Names to get full
if(grade == "A") //Check other grades as well.
data.emplace(fname,grade);
}
while(1){
string option;
std::cout << "Options:" << endl;
cin >> option;
//Your option selection code here
}
return 0;
}
EDIT:
maps are also sorted by key name so printing alphabetically is very easy, no sorting required.
for(auto& pairs : data)
cout << pairs.first << " " << pairs.second << endl;

Does my source code shows my own understanding of structures in c++? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'd like to know if I am in fact in the right direction, I am currently learning the C++ language and reading this book called Jumping into C++ by Alex Allain and there's a practice problem at the end of the chapter regarding structures, to create a contact book program the user should be able to not just fill out a single structure, but should be able to add new entries, each with a separate name and phone number. Let the user add as many entries as he or she wants—is this easy to do? Add the ability to display all, or some of the entries, letting the user browse the list of entries.
so far below is what I've done, I'd like to know if my source code is in fact right and does it show my understanding about structures and overall c++?
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
struct user{
string name;
int phone_num;
};
int _tmain(int argc, _TCHAR* argv[])
{
int input, number; // will hold the users input at the beginning of the program
int counter = 0; // keep track of the array position
int const arraySize = 10; // size of the array
user new_username[arraySize]; // will hold the users details
string name; // will hold the users input for the name
cout << "CONTACTS\n";
do{
cout << "+ADD [1] -EXIT[0]";
cin >> input;
if(input == 1){
//cout << counter;
cout << "\nName: ";
cin >> name;
new_username[counter].name += name;
cout << endl << "\nPhone: ";
cin >> number;
new_username[counter].phone_num = number;
counter++;
//set_user(counter);
}
cout << "Name Number\n";
cout << "--------------\n";
for(int j=0; j < arraySize; j++){
cout << new_username[j].name;
cout << " -- ";
cout << new_username[j].phone_num;
cout << "\n";
}
cout << "\n";
}while(input != 0);
cout << "\n";
system("PAUSE");
return 0;
}
Stackoverflow isn't meant to be used for code reviews, but there's a different site for this (although still in beta): https://codereview.stackexchange.com/
Just some quick things I noticed:
Your program ignores invalid input (enter 2, 3 or any other number instead of 1 or 0).
You don't check whether your user array is full.
This is not really object oriented.
As for basic understanding... I guess yes, but that's not actually hard to start with.
To fulfill "allow the user to add as many entries as they want" you'll have to use a dynamic array (ask the user how many entries he'd like to add) or use some dynamic storage (e.g. a linked list).
If you want the user to be able to add as many contacts as he/she wants, you can use powerful standard template mechanisms.
For this application, I would recommend looking at either
std::vector
or
std::map
This is how you would use them: (keep in mind this is pseudo code and won't compile)
#include <vector>
typedef struct {
std::string name;
double phoneNumber;
} YourStruct;
int main( int argc, char **argv ) {
std::vector<YourStruct> structVector;
do {
int input;
std::cin >> input;
if (input) {
//(read user input for name and number)
YourStruct yourStruct;
yourStruct.name = (user input)
yourStruct.phoneNumber = (user input)
// insert into the vector
structVector.push_back(yourStruct)
}
} while (input != 0)
// now to print what you have:
for (int i = 0; i < structVector.size(); i++) {
std::cout << structVector[i].name << ", " << structVector[i].number << std::endl;
}
}
The benefit to using vectors is that it automatically resizes and keeps track of how large it is without you having to use a counter item.
Now, for something a bit trickier. We're going to use a map to use the "key" value to get the name. The following code won't compile but it is functionally how you would perform the task:
#include <map>
int main(int argc, char** argv) {
std::map<std::string,double> myMap;
// the string is the "key" value, which can be the name of the person
// while the "independent" is the phone number
do {
// determine if the user wants to put another entry in the map
if (insert) {
std::string name = (user input name)
double number = (user input number)
myMap[name] = number;
}
} while (input != 0)
// now we can iterate through the map
std::map<std::string,double>::iterator it;
for (it = myMap.begin(); it != myMap.end(); ++it) {
std::cout << it.first << ", " << it.second << std::endl;
}
// also, you can look up by name
it = myMap.find("Tony Stark");
if (it != myMap.end()) { // if this condition is met, it means you found one
std::cout << it.first << ", " << it.second << std::endl;
}
}
Overall, your code looks good. However, it is not C++. You're programming like a C programmer. The beauty of C++ (besides polymophisim, of course) is the powerful template libraries.
I've just given you a small taste of what you can do with templates. Please comment if you have any questions of concerns. We've all been where you are, kudos for teaching yourself out of a book.
From your question and the code it seems like you are a new programmer, therefore I'll explain you the answer and I'll give you some notes on your code.
In order to solve the problem of "as many items" there are few approaches. The most easy one, and probably a pretty good solution is to use map, in any language it have different names. But usually the name is dictionary, associative arrays...
Using the map will help you with dealing with:
As many items
Sorted order by name
It will be easier for you to filter, it depends what you would like to do, and how sophisticated is your filter.
The other approaches I talked about i though of, are much more basic, and consist much more code, but they give you the feeling of how you can implement the map object by yourself, but this is a different question.
In the link I mention above, the example is for phone entry. But if you still want to use struct, you can have the key as the name and the value to be the struct itself. One justification for that can be that later on you plan to add address and company name.
Some notes regarding your code.
#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
//use meanigful name, instead of user it can be phoneEntry
struct user{
string name;
//Starting using the following conventions using the capital letter in variable names for example phoneNumber
//int won't be god for phone number since some times you will need star or hash, or a leading zero, maybe a plus sign. It is better touse string for tat as well. And of course every time that you get a user input you should validate it
int phone_num;
};
//Why the name of the function is not main, why its _tmain
int _tmain(int argc, _TCHAR* argv[])
{
//Keep going with your comments, with time you would imbrase your own style based on things that you will see. But in general commenting is very important
//Give meanigful name, instead input userCommand for example
int input, number; // will hold the users input at the beginning of the program
int counter = 0; // keep track of the array position
int const arraySize = 10; // size of the array
//Again meangful names
user new_username[arraySize]; // will hold the users details
string name; // will hold the users input for the name
cout << "CONTACTS\n";
do{
cout << "+ADD [1] -EXIT[0]";
cin >> input;
if(input == 1){
//cout << counter;
cout << "\nName: ";
cin >> name;
new_username[counter].name += name;
cout << endl << "\nPhone: ";
cin >> number;
new_username[counter].phone_num = number;
counter++;
//set_user(counter);
}
cout << "Name Number\n";
cout << "--------------\n";
for(int j=0; j < arraySize; j++){
cout << new_username[j].name;
cout << " -- ";
cout << new_username[j].phone_num;
cout << "\n";
}
cout << "\n";
}while(input != 0);
cout << "\n";
system("PAUSE");
return 0;
}
I hope it helped