For a program I am required to use a cin that accepts 4 variables. The first describes a function such as add(), remove(), print(), or quit(). The problem is that to use add() I need to input all 4 variables but for remove(), only 2 variable input is needed.
I want the input to be "add 9 James Bond"
or be "remove 341"
Here is my current code.
int command(string command, int Id, string first, string last){
while (command != "quit"){
cout << "customers> ";
cin >> command >> Id >> first >> last;
if (command == "add")
Basically I do not want to use a menu, instead just accept either an float or a single character. Then send the data to the appropriate spot based on the user input. I have been unable to convert the char to a float, and even if I did the char would probably only accept the first digit, say user enters '15' it would only read the '1'. I've tried strings instead of char but then unable to use the isalpha function. Do I need a char[] and then iterate through to get the numeric data? Then how do i make '1' and '5' become 15. There is probably a solution. I've also tried to use a loop waiting for the correct data while(!(cin >> letter)) which works but how do I get out if the user enters number.
It's not something trivial but I would like to know the best way to process multiple outputs, for example:
Input First line of input will contain a number T = number of test cases. Following lines will contain a string each.
Output For each string, print on a single line, "UNIQUE" - if the characters are all unique, else print "NOT UNIQUE"
Sample Input 3 DELHI london #include<iostream>
Sample Output UNIQUE NOT UNIQUE NOT UNIQUE
So how can I accomplish outputs like that? My code so far is:
Code: int main(int argc, char *argv[]) { int inputs, count=0; char str[100]; char *ptr; scanf("%d",&inputs);
[Code] ....
But the above will obviously print the output after each input, so I want to know how can I achieve the result given in the problem. Also another thing I want to know is, I am using an array of 100 char, which it can hold a string up to 100 characters, but what do I have to do if I want to handle string with no limit? Just declaring char *str is no good, so what to do?
I am beginner at C and I was working on a program where I have to read in a line such as Digit, String, Float. The string can have any amount of spaces between it. and each input is separated by a space character.
The input is of the format:
10000000000 hello my n ame is 30.2
So I used fgets(x,100,stdin) to read the line in.
So I need to read that line into an int, array, and float.. so I was thinking of using this:
I have a C++ code reading large data from an input txt file, doing some calculation on the data, and writing the result of calculation in another txt file.
I have about 300 input files, and the calculation time for each input file is pretty long (~4 days on a single CPU), so I would like to run the same code on multiple CPUs for different inputs.
Which is the most appropriate strategy in this case, multithreading, mpi or something else?
am trying to create a program that asks the user personal questions.
std::vector<std::string> name, age, favsinger; std::cout << "Hello, what is your Name Age Favorite_Singer? "; std::cin << name; //i want to store the user's info along with the sibling's
In order to make things easier in the long run you have decided to make a c++ program that takes in all the orders for each register and tallies them at the end of the day.
Write a c++ program that does the following:
Create a Register class that can store all of the receipts for the day and the totals for that register.
This class could have the following member functions:
Contructor(int) - Creates a number of receipts based on an integer that is passed into the constructor (this is the largest number of orders that the register can take). You may also be required to create additional variables to make the program work but that's up to you to determine.
void getorder() - Asks the user how many of each item they want an stores that in the first available receipt.
void returnreceipts() - This function returns the details of all the receipts and the total for the day.
Register operator+(const Register &right)- This is an overloaded addition operator. When two objects are added together an empty temporary register is created (with 0 receipts) and only the totals of both objects are added to it. The temporary register is returned by the function.
Register operator=(const Register &right)- This overloaded assignment operator copies only the totals from the Object on the right.
In the Main function I would like:
Create 3 Register Objects. The first two registers are the ones in the store and should be initialized to take 10 orders. The third is used at closing time and can be initialized with 0 receipts as it will only take in the totals from the other registers.
Run the getorder function for registers 1 and 2 twice. Run returnreceipts for register 1 and register2. Reg3=Reg1+Reg2; Run returnreceipts for register 3.
[Code]...
this is what I have so far I'm trying to get the input part working first, so the user would be asked each item individual how many they want? this will happen for 2 users, then the next register will do the same?
I want to accept numbers from the user into an array and convert into corresponding alphabets. E.g 1 into A, 2 into B, and so on.
This is simple, but the problem is the user is supposed to enter the character # also which I want to display as it is in the output. How can I do this ? What type of array should be used - int or char?
I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.
What I want to do with my program is I want my length, width,volume and price to accept number values only. This is what I have so far.
// This program calculates and displays the pool's volume // the amount of water needed and the cost.
#include <iostream> #include <iomanip> using namespace std; int main() { // the double type accepts numbers including fractions for the following inputs. double length, width, depth, poolvolume, watervolume, price;
I was trying to look up solution for this for quite a while already but found nothing. I am writing a simple console based turn based RPG game for my class project. I was trying to have a member function attack() in class of the player character, which affects the component called health of the class Enemy. both this classes are inherited from the base class Unit. I tried to pass the object of type enemy as an argument to the function attack, but the function call gives me Error: too many arguments in function call. Here's the code for classes:
class Program { //Accept two input parameter and returns two out value public static void rect(int len, int width, out int area, out int perimeter) { area = len * width; perimeter = 2 * (len + width);
[Code] .....
why is the static keyword required in the method signature for the rect() method. It will not compile if it is absent. why?
the same is true for this example:
class Program { static void printvalues(params int[] passedin) { foreach (var printthis in passedin) { Console.WriteLine(printthis);
[Code] ....
This code won't compile without the static keyword in the printvalues() method signature. why?
I am creating a WinForm registration application and my program accepts user input information and stores it but I am struggling to use my login function. I believe there is an error in the area of cmd.Parameters.AddWithValue section, I dont think addwithvalue is correct ? I get a fatal crash has occurred when I click Login
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome"; string Query = "SELECT * FROM 'userinfo'.'users' where 'username' = @userid and 'password' = @password)"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmd = new MySqlCommand(Query, conDatabase); cmd.Parameters.AddWithValue("@userid", this.userid_txt.Text); cmd.Parameters.AddWithValue("@passone", this.passone_txt.Text);
[code]....
Fixed the crash error, simple typo but now I am getting SQL Syntax errors which I originally believed I fixed.
I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?
I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?
#include <iostream> #include <iomanip> using namespace std;
// Function Prototype void sortArray(int array[], int size);
[Code] ....
This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0
if n = 6 0 1==0 2==1==0 3==2==1==0 4==3==2==1==0 5==4==3==2==1==0 6==5==4==3==2==1==0