C++ :: How To Get User Input To Be Stored In 1 Out Of X Variables

Dec 5, 2013

Making a game of checkers on C++ win32, visual studio

when i want a piece to move, i type:

cout << "What piece do you want to move? (C4)" << endl;

i type in 'cin' after to get the players input, but how do i get it to store the players input in a certain variable? im going to have a list of variables:

string a1
string a2
string a3

etc

so if the user types in a2, it automatically goes to that variable and then asks the user "where do you want the piece to be moved to?".

View 6 Replies


ADVERTISEMENT

C++ :: Force Variables To Be Stored In Char Array

Jan 7, 2015

I want to declare a char* array, and then make any future variables declared to be stored in a specific location within the char* array. Is this even possible, and if it is how would I go about doing it. (I plan on storing any primitive data type in it (not classes or structs), and they may signed or unsigned).....

View 12 Replies View Related

C++ :: Printing Out A Cout Statement Using Stored Variables

Feb 9, 2015

Im trying to run my program and it works fine until the very end where I want it to read "<name> is a <gender> citizen of <nation>." with the corresponding variables. Here is my work for the time being. Also is there a way to make it where if someone puts a M or m for gender, it will spit out Male instead of just m or M.

#include <iostream>
using namespace std;
int main()
{
char gender;

[Code].....

View 2 Replies View Related

C/C++ :: Force Variables To Be Stored In Char Array

Jan 7, 2015

I want to declare a char* array, and then make any future variables declared to be stored in a specific location within the char* array. Is this even possible, and if it is how would I go about doing it (I plan on storing any primitive data type in it (no classes or structs), and they may signed or unsigned). I want to be able to use the variables like any other variable, I just want the variable's address to be within the char* array.

I am trying to make a program that is similar to a virtual machine and an emulator put together, and it can only run one os (which will be hard-coded into to the program). The reason I wanted to do this is because it would be the easiest way to make sure that all variables in memory are in one contiguous block, that way the part that manages memory wouldn't have to store the locations of each variable (which would have been necessary for the virtual memory manager).

An example of what I am wanting to do is

char* ram [256]; // Address 0x00 to 0xff

// Code to make sure that new variables' addresses are in ram[] if necessary

unsigned short a = 5; // Gets stored at address 0x00

unsigned int b = a; // Gets stored at address 0x00+sizeof(a)

View 1 Replies View Related

C :: Why Constants And Variables Stored In Memory In Opposite Order Called

May 23, 2014

I'm playing around and wrote a tiny program.

Code:

char bracketin[] = "thisgetsbracketed.txt";
char bracketout[] = "bracketed.txt";
char testwalk[10] = "12345678";

[Code]....

I'm incrementing the pointer to buffer 150 bytes beyond its reserved 50. I see testwalk, followed by bracketout, followed by bracketin printed by the overflow on buffer.

The memory locations are ordered descending from their call order. Why is this the case?

One would think that they would be written in ascending order as I call them. I can only assume that they're compiled bottom up - where could I read about this process?

View 3 Replies View Related

C :: User To Enter 4 Integers Which Get Stored In Array

Mar 3, 2014

For my code, I want the user to enter 4 integers, which get stored in an array. Here are the lines I wrote relevant to this part:

Code:
printf("Enter 4 integers:
");
scanf("%d %d %d %d," &a, &b, &c, &d);
z[4] = { a, b, c, d};

Would this be correct?

View 5 Replies View Related

C/C++ :: Iterate Through Array And Search For A Number That Was Stored By User

Nov 23, 2014

So I have an issue with a homework assignment that I am coding. I am attempting to get a function to iterate through an array and search for a number that was stored in an array by the user. So far I can take the number, get the numbers displayed but in my menuChoice2 function, for some reason the program is not confirming whether or not the number is entered, and is only telling me that the number has not been found, instead of confirming that the number is in the array.

Here is my code thusfar:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Variables that are Globally declared
int menuChoice = 0;
int usernum[1000] = { ' ' };

[Code] .....

To be clear I am not getting any errors but something is telling me that the error is in the formatting of menuChoice2.

View 14 Replies View Related

C++ :: Write A Calculator - User Will Enter Terms And They Will Be Stored In Arrays

Jun 14, 2013

i'm trying to write a calculator. the user will enter the terms and they will be stored in arrays. i will be storing those terms in string arrays and then later turn them to double to work with them. but the user should be able to enter terms like sin(252) and the program should be able to recognize it and calculate it.

View 4 Replies View Related

C++ :: Multiple Quiz Program - Adding High Score For Each User Stored In Binary File

Jul 11, 2014

I am making a multiple quiz program. So everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.

class user { //The collection of all info pertaining to the users
char user_id[50];
public:
int hscore1;
user() {
strcpy(user_id,"NULL");
hscore=0;

[Code] ....

View 1 Replies View Related

C++ :: Create Simple Input Interface On Console - Allow To Input Values To Variables

Apr 6, 2013

I am trying to create a simple interface on console to allow to input some values to some variables. For ex:

int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
string x;

[Code] ....

However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.

View 2 Replies View Related

C++ :: User Array Size And Sorting User Input

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

C++ :: How To Input Two Variables From Same Line

May 27, 2014

How to input two variables in the same line? Like when i type 12 and press enter, 1 must be assigned to a, and 2 must be assigned to b. I want it to be entered on the same line, and press enter only once. How do i do that?

View 5 Replies View Related

Visual C++ :: Re-input Variables After Loop Ended

Oct 18, 2014

I just started programming and want to make the game cows and bulls. The problem is that after the loop has ended and both vectors are not the same I want the user to 're-input' the starting variables a,b,c&d but I don't know how to.

Code:
#include "std_lib_facilities.h"
int comparison(int a, int b, int c, int d)
{
vector<int>bc={ 1, 2, 4, 9 };

[Code].....

View 2 Replies View Related

C/C++ :: Compare Values Stored In First Array To User Inputted Values In Second Array

Oct 19, 2014

Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.

In order to fix this error: [URL]...

I had to change my array initialization to one with a star in front of it:

char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
to:
char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};

I also changed my 2nd array to one with a star in front of it: char *a2[20];

What does this mean exactly? Putting a star in front of an array?

Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array:

cin>>a2[i];

View 3 Replies View Related

C++ :: Second User Name Input Is Being Skipped

Jan 1, 2014

In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.

So while running the program it looks something like:

What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>

Here's my code:

Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;

[code].....

View 9 Replies View Related

C# :: TexBox User Input To Hex Value

Sep 2, 2012

So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:

Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer

if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode

[Code] ....

I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.

View 4 Replies View Related

C :: User Input To File

Mar 18, 2013

I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....

View 2 Replies View Related

C :: User Input With Forks

Apr 7, 2013

So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.

Code:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <stdbool.h>

int main() {
int j, i,pid;

[Code] .....

View 2 Replies View Related

C++ :: Alter User Input

Feb 6, 2013

I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.

#include <cstring>
#include <iostream>
using namespace std;
int main ()

[code]....

View 7 Replies View Related

C++ :: Trying To Get User Input Into Array

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

C++ :: Divide User Input By 2 Until 1

Nov 10, 2014

I need to make a program that takes in a user’s number and keep dividing it by 2 until it is 1.I need to display the division steps ...

I do not know how to keep making it divide by 2 until 1. I tired this but it obviously did not work..

Code:
#include <iostream>
using namespace std;
int main() {
//User Input
int input,total;
cout <<"Enter A Number To Be Divided By 2 Until 1" << endl << endl;

[Code] ....

View 7 Replies View Related

C++ :: Cin Not Waiting For User Input

Apr 21, 2013

since around 2hours im really fighting with the cin command.It doesn't matter what exactly im trying, it's just not waiting for user input and keeps directly using 0 as "entered" value.

int Value;
cout << "Enter a new value: " << endl;
cin >> Value;
cout << "The value has been set to: " << Value;

View 4 Replies View Related

C++ :: CMD Closes After User Input

Jun 7, 2014

I'm trying to make a simple program that accepts user input, simple stuff. When the user (me) enters a number to be sent to the console and i press enter so it accepts the data, it closes the command prompt and thus ending the program. I just need to find a key that i can use to continue but doesn't close cmd.

View 5 Replies View Related

C++ :: How To Tell Whether User Input Has Already Been Used In 2D Array

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

C++ :: User Input In Italics

Oct 10, 2014

I am a beginner in C++. The program I want to create is as follows. The program will take a sentence as input from the user in italics and display it.

The output will be:
Enter a sentence :
Hello World!
You have entered : Hello World!

How to take user input in italics.

View 6 Replies View Related

C/C++ :: Print Out User Input

May 17, 2014

Create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format: your name is (blank), you are (blank) years old, and your username is (blank).

So I started making my program

#include <stdio.h>
int main(int argc, char* argv[]) {
char name;
int age;
char username;
printf("Please input your name,your age,and reddit username");
scanf(" %c %d %c", &name, &age, &username);
printf(" %c %d %c", name, age, username);
return 0;
}

My program outputted H 0 and an upside down question mark. I was thinking that maybe the error in the program was that i was supposed to use %s instead of %c but im not entirely too sure.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved