C/C++ :: Program That Keeps Reading Integers Until User Enters -1

Nov 21, 2014

This is the problem :- Write a program that keeps reading integers until user enters -1, then it prints the maximum and the minimum among all numbers (-1 should be ignored).

View 14 Replies


ADVERTISEMENT

C/C++ :: Writing Program For Class Where User Enters Their Age?

Aug 18, 2014

I am writing a program for a class where the user enters their age, how much money they have, and their full name. I know that I have to use the getline method to get the user's full name, and I know that I have to use cin.ignore() before that code, but i'm not sure why I have to use cin.ignore()?

View 1 Replies View Related

C++ :: Reverse Polish Calculator - How To Make Program Exit If User Enters Only 0

Oct 11, 2013

I have my Reverse Polish calculator compiling and everything but for the assignment I need to handle a few exceptions that I can't seem to get. First off I'm trying to make the program exit if the user enters only "0" but since the input i'm using is string, I cant figure out how to code

"If the first node is 0 and the next node = NULL, return true"

Here is my code:
#include<iomanip>
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string>
#include<sstream>
using namespace std;

class Stack {

[Code] .....

View 1 Replies View Related

C++ :: Keep Looping Until User Enters A Blank Line?

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

C++ :: Keep Looping Until User Enters A Blank Line?

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

C++ :: Program To Create Integers As User Requests?

Nov 19, 2013

I know it would be easier to create an int array, but I want the program to create integers as the user requests. For example, if the user enters 4, the program creates 4 integers with the names input. Each integer is better as an individual integer, not an element in an array.I'm not sure if this is a possibility with C++.

View 3 Replies View Related

C :: Program That Asks The User To Type 10 Integers Of Array?

Mar 2, 2014

Write a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."

(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.

I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?

View 4 Replies View Related

C :: Program That Takes Multiple Integers From User And Finds Minimum Value

Jun 11, 2014

Write a C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.

This is a sample output. Notice how the program prints a counter (1, 2, 3, ) for user keep track of how many numbers were entered so far. Include this feature in your program.

I have tried different ways to get the result from while loops, do while, and if-else statements. We have not done any max/min problem in class and the book was kind of vague. We have not learned arrays yet in class and I can't figure a way to compare the integers the user inputs as it is an infinite(from what I am reading) amount aloud. The problem I am seeing is the loop works and stops with the sentinel value but the INT_MIN is using the sentinel value. I also have not addressed the input of negative numbers yet with the first program I wrote, maybe one of my problems.

Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>
/*****start program*****/
int main() {

[Code] ....

I have also tried this way as well, min value still comes back as -1 the sentinel value, and the else statement is being ignored. I am sure it is something silly but I am lost and confused at this point.

Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>

[Code] ....

View 13 Replies View Related

C :: Program To Get Series Of Integers From A User And Storing Those Values Into Array

Feb 10, 2013

The problem deals with writing a program to geta series of integers from a user and storing those values into an array. Then use a function called selection_sort, when given an array with n elements, the function must sort the array from smallest to largest values.

I have code, and im trying to get it to compile but im getting these implicit declaration errors and conflicting types. Here is my code and the compiler errors.

Code:
Compilation started at Sun Feb 10 20:14:48

gcc -Wall -o ex9-1 ex9-1.c
ex9-1.c: In function 'main':
ex9-1.c:16:5: warning: implicit declaration of function 'selection_sort' [-Wimplicit-function-declaration]
ex9-1.c:20:2: warning: implicit declaration of function 'prinf' [-Wimplicit-function-declaration]
ex9-1.c: At top level:

[Code] ...

Compilation exited abnormally with code 1 at Sun Feb 10 20:14:49

Code:
#include <stdio.h>
int main(void) {
int a[100], i, j, N;
printf("How many numbers will you be entering: ");
scanf("%d", &N);

[Code] .....

View 4 Replies View Related

C++ :: Program Read In 15 Integers From User Then Store And Print Out Numbers

Apr 29, 2014

I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.

View 7 Replies View Related

C++ :: Program Enters If Statement Even Though Requirements Not Met

Jul 25, 2014

My program gets user input and compares it against an array of characters (guessLetters[x]) to decide whether the do/while loop repeats. The whole character array contains underscores yet if i enter any letter it goes into the if statement and repeats the do/while loop.

do {
repeatflag = false;
cin >> UserInput;
UserInput = toupper(UserInput);

[Code] .....

View 2 Replies View Related

C++ :: Truth Table Generator - If User Enters String Of Boolean Algebra It Will Output Table

Jan 25, 2013

If a user enters a string of boolean algebra it will ouput the table.

I have input parsing, cycling through the combinations, and outputing working. However once i parse the input I am not sure what to do with it. I have thought of having it write the parsed input to a new file as a function and then use that function, but that seems bad.

How to dynamically create the function, how to implement it.

BTW This is a console function, if that changes anything.

View 2 Replies View Related

C# :: How To Autogenerate Employee Id When User Enters Details Of Employee

Jul 4, 2013

I want to autogenerate employee id when user enters details of employee

Conditions:

User Selects Department which should be used as prefix.

A new Sequence of numbers must be generated for each department

Example:
DeptA0001
DeptA0002
Again DeptB new seuquence must be started
DeptB0001
DeptB0002...

View 3 Replies View Related

C :: Reading Integers That Are In A String?

Dec 3, 2013

I am doing a program and i need to read integers that are in a string and i dont know if i am doing it correctly.

Code:
unsigned int j=0, h1;
char num[100] , str1[100], str2[100], a[100], b[100];

sscanf(str1, "%[^;] ; %[^;] ; %d ", a, b, &h1); the string is : "0048915433190;24/10/2013;13h 7m 47s;13h 8m 59s;0;1;"

And what i want to read with sscanf is the hours, minutes and seconds.

View 1 Replies View Related

C++ :: Reading Integers From File And Storing Into Array?

Oct 28, 2014

My main issue is that when I store just one value into a simple integer variable, it gives me a big negative number.

My goal is to store a file that reads like this into arrays:

2014 1 23
2012 2 15
2013 1 25
etc

Where I would have the first column in an array, the second in another and the third in third array since I am not allowed to use multidimensional.

View 5 Replies View Related

C/C++ :: Reading Unknown Number Of Integers In A Line?

Mar 1, 2015

I have a file with such a format:

string string 8 7 2
string string 7 12 19 -4
string string 1

As you can see I don't know how many numbers there are at the end. I have this code now:

while(!in.eof()) {
kr = 0;
getline(in, pavard, ','); getline(in, vard, ','); getline(in, gr, ',');
while(in.peek()) {
in >> k;
kr += k;
}
in.ignore();
}
in.close();

I tried various combinations with peek() function, but nothing worked.

View 2 Replies View Related

C++ :: Reading Integers Out Of A Text File And Only Adds Positive Ones?

Sep 26, 2014

I'm basically trying to make a simple program that reads integers out of a text file and only adds the positive ones and not the negatives.

All is well except it won't take the last integer (the last line, I presume.) I took the negative out, nothing to do with that. I put more numbers in and I made the txt file less, no answer. No matter what the last number is, the program won't read it. I've been researching online and I've been seeing that it might be an issue with "while "!inFile.eof())".

Anyway here's the program:

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile;

[Code] .....

Here's the txt file:
5
6
-9
21
3

I'm always getting 32 for some reason.

View 2 Replies View Related

C :: Reading And Printing In A Specific Format Strings Of Characters And Integers

Feb 23, 2015

I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.

On to my question... How do I read multiple lines with both carecters and integers. for instance:

nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998

I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data

but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.

this is what I have tried.

Code: scanf("%s %s", &make,&year);

//The way I seen to read multiple lines was on here

scanf("%[^/t]", %make);

But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.

View 1 Replies View Related

C++ :: Using While Loops That Prompts User For A Set Of Integers

Jan 30, 2015

-Write a program using while loops that prompts the user for a set of integers.

-Your program will ask for one integer at a time. If the number 0 is entered, the list is complete and your program will output two results: the sum of the even integers and the sum of the odd integers.

-After each integer is entered by the user, your program will print out whether the integer entered by the user is less than, equal to, or greater than the previous integer. Assume for the first integer entered by the user that the “previous integer” was 0.

-Your program must handle a variable number of inputs (in other words, you cannot hard code for the test cases).

This is what I have so far:

#include <iostream>
using namespace std;
int main() {
int a;
int b;

[Code] .....

View 2 Replies View Related

C++ :: Reading From Console Multiple Strings Of Unknown Length In Combination With Integers

Oct 10, 2014

I want to read a string of unknown length from stdin. I tried to follow the approach from this link.

[URL]....

My code is like this:

Code:

#include <iostream>
#include <string>
using namespace std;
int n;
cin >> n;
cout << "The value of n is " << n << endl;
string str;
getline(cin, str);
cout << "The entereed string is " << str << endl;

What I have noticed is that if I take integer input from cin (cin >> n in the above code before getline, the control does not stop on getline to take str as input from the console. If I don't do (cin >> n) before getline then the control stops on getline and takes the string as input.

What is the best way to read from console multiple strings of unknown length in combination with the integers?

View 1 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++ :: Add Or Remove Integer To A Chain Of Integers Created By User

Mar 25, 2014

I got everything in this code running except for my remove function. What the project does is adds or removes an integer to a chain of integers created by the user. My add function works the first time but after that if I try to remove or add I believe it is pointing to the improper location and I don't know how to fix this....

Here is my code:

Header:
// adds "number" to the array pointed to by "arrayPtr" of "size".
// Note the size of the array is thus increased.
void addNumber(int *& arrayPtr, int number, int &size);
// removes a "number" from the "arrayPtr" of "size".
// if "number" is not there -- no action

[Code] .....

View 12 Replies View Related

C++ :: Output Multiplication Table From Two User Input Integers Between 2 And 10?

Jan 14, 2015

So I'm supposed to write something that will output a multiplication table from two user input integers between 2 and 10.

For example it should display like this is the user inputs 4 and 5

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20

I was hinted to used two for loops and this is what I have thus far, what I can't figure out is how to display it like the example.

#include <iostream>
using namespace std;
int main() {
int num1;
int num2;
cout << "Enter two numbers between 2 and 10." << endl;

[Code] .....

View 2 Replies View Related

C++ :: User Input 10 Integers Of Array - Add Numbers Greater Or Equal To 10

Oct 29, 2013

create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10.

View 6 Replies View Related

C :: Program Using A Function To Add Two Integers

Dec 2, 2014

I compiled a simple program using a function to add two integers, in order to understand the difference of calling by value vs by reference.

Code:

#include <stdio.h>
int add(int a, int b, int sum);
int main()
{
int a, b, sum;
printf("Please enter two integers
");
scanf("%d%d", &a, &b);

[Code]...

I used these two (one, two) pages I found in the net while studying the subject. So here are my questions...

(a) Do I understand correctly that in the above code all a, b and sum are passed by value?
(b) If I wanted only sum to be passed by reference, how the above code would change?
(c) If I wanted all (a, b, sum) to be passed by reference, how the above code would change?

View 12 Replies View Related

C :: Program To Write Even And Odd Integers Into Different Files

Sep 7, 2014

-Create three files namely all_numbers, odd_number and even_number.
-Get the number of records and the numbers to store from the user.
-Save all the numbers in "all_numbers" file.
-Read each number and check whether it is odd or even.
-Store the odd numbers in odd_number file and even numbers in even_number file.
-Finally, print the numbers stored in odd_number and even_number files.

The output of the program will look like this.

How many records that you want to store :41

2
3
4

The data are written too the respective files.

The even numbers are 2 4
The odd numbers are 1 3

View 9 Replies View Related







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