C/C++ :: User Input Returning As Blank When Using Array Of Structures
Feb 14, 2014
I am having trouble returning use input from iterations after the first series of input from the user. My readCourseArray function can only have one parameter and it is information from the structure Student. This information is gathered from a function which is not in the code below because it works fine. I have hard coded a few lines to try to figure out why I am not getting any input after the first pass of the readCourseArray function. I have tried to delete the tempArray in the function after each pass assuming that that could be the issue. But it was not. At least from what I have gathered. I have tried ignoring new line characters which I never really though was an issue but I tried anyways.
I guess what I am asking is: Is my problem coming from the function itself or from my assignment of the cArray to the return tempArray values?
Like I said, the first pass will print out all of the user input (if I put the code in) but all others will return bad values. I did have a do/while to print out the values but it caused the program to crash. I assume because it hit a bad value and needed to break.
#include <iostream>
#include <string>
using namespace std;
struct Student {
string firstName, lastName, aNumber;
int numberCourses;
double GPA;
[Code] .....
View 2 Replies
ADVERTISEMENT
Nov 18, 2014
I have to create a program that incorporates an array of structures in order to simply read input from the user and then reprint that information to the screen. This is a fairly simple problem, but the issue is that the professor requires that we solve it in a very specific way.
I must have three functions in total: one to receive input from the user, one to print the received values, and of course the main function which calls the other two. Also, the input and output functions must be defined using the following prototypes:
void inputData(Component C1);
void printData(Component *C1);
Where Component is a structure defined above as:
typedef struct// Component {
float cost;
int code;
char name[30];
[Code] ....
I know that this problem could be easily solved by simply passing the entire 'comp' array to the inputData function, or passing a pointer to it, or having it return a pointer, but I am not allowed to do any of these things. I must use the function as defined by the prototype.
View 3 Replies
View Related
Aug 4, 2013
My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:
Code:
do {
cout << "
Enter a name: ";
cin >> input1;
if (input1.empty())
[Code] ....
As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like
Code: if (input1 == "")
but that doesnt work either. How do I break out of this loop?
View 2 Replies
View Related
Aug 4, 2013
So I've run into the following problem. My goal is to create a loop that keeps taking user input over and over until the user doesn't enter anything into 'cin >>', leaves the line blank, and simply presses the ENTER key to move on, at which point the program is supposed to break out of the loop and continue on with the rest of program execution. Something like this:
do {
cout << "
Enter a name: ";
cin >> input1;
if (input1.empty()) {
[Code] .....
As you can see, I've already tried using the empty() function, but that didn't work, the program simply stays in the loop and doesn't break out, no matter how many times I press enter. It just keeps prompting me to enter a name. I've also tried using something like
if (input1 == "")
but that doesn't work either. How do I break out of this loop?
View 1 Replies
View Related
Jan 5, 2015
I have followed the tutorial here - [URL] .....
This is a tutorial that I have gone through completely with success, but now I am trying to create a different project using the same sort of setup.
When I add my usercontrol to the MainWindow it has none of the buttons/TextBlocks on which I have put on the UserControls - It is just a blank box. What could be causing this?
I have changed the name of the project to [snip] because it has a company name in it...
"NumericControl.xaml"
<UserControl x:Class="[snip].UserControl.View.NumericControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
[Code] ....
View 14 Replies
View Related
Nov 1, 2014
I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"
Heres My Code:
//Assignment 19 Program 2
#include <iostream>
using namespace std;
int main()
[Code].....
View 3 Replies
View Related
Jan 28, 2015
Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;
[Code]...
View 3 Replies
View Related
Apr 25, 2014
I have written a program and i had to pass an array into a function and now i have a variable for the subscript of the array and i was the user to input data, specificlly a string, more specifically first and last name without having to create two arrays, i have to do this with other things in the program as well, here is part of the program:
int addFunc(const int totNum, string city[],string state[],string street[],string name[],
int addNum[],int zip[],int telNum[],double bal[],int dateLp[], int addCount, int accNum, int usNum)//function will add a new account {
int countAf = 1;
if (usNum < 20)
[Code] ....
it should be able to take firstname space lastname
View 5 Replies
View Related
Mar 7, 2014
My parameters are that the users input has to be from 1 to 9 and the same number can't be entered twice. How do i modify this code to make sure that the user did those things or an error message should appear that their input is invalid.
#include <iostream>
using namespace std;
int main() {
int square[3][3];
[Code] ......
View 6 Replies
View Related
Mar 28, 2013
Say you the user inputs x number of names and then is to put in x amount of values for each name. How would you display these values in a 2d array and be able to add the values for each row which will represent each name?
View 5 Replies
View Related
Mar 26, 2014
Were supposed to be able to sort an array which is user input, but the first number they input is supposed to be the length of the array, and everything after that is the actual array.
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int size;
int list[80];
bool isSorted (const int list[], int size);
[code]....
I'm stuck on how I'm supposed to use the first digit of input for the array size.
View 6 Replies
View Related
Oct 2, 2013
I have already data in two dimensional matrix but some cell is empty.Now i want to put 0 in blank cell.
View 2 Replies
View Related
Dec 14, 2014
I'm trying to learn structure type in C. In this trying, the code must take 9 value from user but it takes 6 values then returned. I scrutinized but I can't find my error.
#include <stdio.h>
typedef struct books {
char name;
float price;
int pages;
} book;
[code].....
View 2 Replies
View Related
Mar 19, 2014
I am compiling using Microsoft Visual C++ and I am trying to create a program that ask's the user for 10 numbers, and these numbers will have to be loaded into a one dimensional array of 10 elements. I read up online as well as my book and looked at sample programs, then created mine which was similar to the sample programs I looked at, but the sample ones compile , while I get C2059 and C2061 Syntax Errors. I am new to programming so I understand it could be one small thing but I after looking over it I am completely clueless.
Heres my program:
Code:
#include
<iostream>
int
main()
[Code] .....
My program is also attached
View 5 Replies
View Related
Apr 5, 2013
If the user puts in a 6. I need the array to display the even number from 0 - 6. Right now what it does is it displays the first six even numbers. Okay as I'm writing this I'm starting to see where my problem might be..
Code:
void sumIntegers () {
int arr[50];
int i = 0;
int num = 0;
int sum = 0;
[Code] .....
View 1 Replies
View Related
Oct 11, 2013
I am trying to create a global array with user-defined dimensions.the code is:
Code:
int matr_size()
{
int x = 0;
printf("Please enter the number of nodes: ");
scanf( "%d", &x);
printf("There are %d nodes in this simulation.", x);
getchar();
return x;
}
[code]....
I read that an array cannot be defined by a variable in C so I assume that is the issue, but I'm not sure how else to do it. Previously the size was defined by #define NODES and it worked fine but I need this user input.
View 5 Replies
View Related
Nov 8, 2014
I'm trying to code the program that will store item data.And I'm having problems to receive user-input string to array.
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iomanip>
using namespace std;
[code].....
View 6 Replies
View Related
Oct 25, 2013
I have been reading up on arrays and string array. I created a string string text[0] and it is defined by user input. I am trying to sort the input. I want Michael to read Macehil.
When I wasn't using an array and just a string I did this:
return sort(text.begin(), text.end()); a
And it worked fine. Do I need to change my string into a char? If so, would I static cast that?
View 9 Replies
View Related
Mar 20, 2014
how to do this? ask the user to input entries of 10x10 array. sort each column into increasing order. print out the array with sorted columns?
View 5 Replies
View Related
Jul 2, 2013
int main() {
char StudentName[4][10] = { "Hermine", "Paul", "Gertrude", "Leon" };
cout << "Student Names";
cout << "
Student 1: " << StudentName[0];
[Code] ....
This code work fine...but i want to take name from user..how i store it in character array through getline()..
View 6 Replies
View Related
Apr 27, 2014
So I'm trying to make a program, Which has nothing to do with the topic. But I ran into a problem.
I need to get a char array size of 6 doing:
char myChar[6];
but the size (6) is undefined until user input.
So I need to do char myChar[var]; (Var being 6 for now).
When I do:
char myChar[6];
It works!!!
But when I do:
int val = 6;
char myChar[val];
It doesn't work.
View 3 Replies
View Related
Aug 29, 2013
I am writing code for a program that will take user input selection of columns and determine an array based on that.The number of columns will be user selected.The number of rows equals 3^(columns) <--exponent not XOR
- This is because each column has the possibility of having the numbers 0,1,or 2
For example, if the user were to select "4" columns, then the array would have 4 columns and 3^4=81 rows. Then I would like to populate this with all of the possible combinations of 0,1,2
i.e.
0000
0001
0002
0010
0011
0012
0020
0021
0022
0100
....
2220
2221
2222
how I would create the "For" Loop for this?
View 19 Replies
View Related
Jan 10, 2015
I'm coding a hangman game. I'm trying to store user entries so i can output them to show the user what they have already entered. Problem is that it's not display anything at all.
I'm trying to store multiple characters of course, and then display all characters stored.
char guess[27]={0};
cin >> guess[26];
int hit=0;
for(int i=0; i<len; i++) {
if( guess[26] == hidden_word[i] ) {
hit++;
select_word[i] = guess[26];
if(strcmp(hidden_word,select_word) == 0) {
[code]....
EDIT: I also get the error - Stack around the variable 'guess' was corrupted. At the end of the game.
View 6 Replies
View Related
Sep 30, 2013
How would you search in a vector array from a user input string?
ex: user input : "Hello"
output: search vector array and find the line that has the string "Hello" and output the array "Hello" is on?
View 1 Replies
View Related
Sep 25, 2013
I'm trying to build an array of a certain size, after receiving user input. The method I'm trying is
int var = 3;
int* ar = new int[var];
When doing tests I did this (and it worked) and red flags popped off in my head.
int var = 3;
int* ar = new int[var];
ar[0] = 0;
ar[1] = 1;
ar[2] = 2;
ar[3] = 3;
ar[4] = 4;
cout << ar[0] << ar[1] << ar[2] << ar[3] << ar[4] << endl;
This method is considered safe, and possibly tell me why I'm not getting stack errors when trying to overload the array?
View 9 Replies
View Related
Apr 29, 2012
Question simple like that: Let user enter some words from keyboard, one word per line until a '.' (period) entered then print out result, for example:
Code:
Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2
Problem is I don't know how to declare the array of character at the beginning since I don't know neither how many word user may enter nor how many letter of each word. So I go ahead and declared like this: char word[20][50] but I know it is not best way.
Code:
int main () {
char word[20][50]; //array has maximum 20 words, each word maximum 50 character
int i=0, number_of_word;
do {
printf ("Enter a word: ");
[Code] ....
View 3 Replies
View Related