C/C++ :: Program Crashes After Numbers Input From User

May 6, 2014

#include <iostream>
#include <string>
#include <limits> //for std: numeric limits
#include <algorithm>
//Function to get an integer from the user that is greater than or equal to zero.

int getPositiveIntFromUser(const std::string& prompt) {
int retVal = -1;

[Code] ....

The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!

View 2 Replies


ADVERTISEMENT

C/C++ :: Program That Will Print Numbers In Columns From User Input

Oct 7, 2014

I tried to work on this program for while, but I am not able to get it to work

Directions:Write a program that reads an integer n from the user.

Display the first 100 numbers, with newlines every n numbers, using % operator

#include <stdio.h>
int main(void){
int a = 0;
int b = 99;
printf("Enter a number: ");
scanf ("%d", &a);

[Code] ....

When I run this code it asks me to enter a number. It doesn't matter what number I enter it gives me the numbers from 1 to 100 in one horizontal line.

I want this program to do something like this:

for example if the user enters n=6 the program should give:

0 1 2 3 4 5 6
7 8 9 10 11 12 13
and so on

View 2 Replies View Related

Visual C++ :: Write A Program Where The User Will Input Integer Numbers?

Oct 21, 2014

I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.

Create a dynamic array if the size=2( the initial size must be 2) Repeat until user enters -1.

I have to do this without using vectors.

This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?

Code:
#include <iostream>
using namespace std;
void resize(int *[], int);
int main() {
int *listDyn;
int size=2;

[code].....

View 5 Replies View Related

C++ :: Program Crashes After Input - Terminated Called

Oct 28, 2013

My programs complies and runs. However, whenever i try to enter something when prompt to enter the number of accounts i wanted to create my program crashes.

By the way, im using codeblocks.

it says

terminated called after throwing an instance of 'std:: out of range'. what(): basic_string::substr"

Code:
#include <iostream>
#include "clsInterest.h"
#include "clsDate.h"
using namespace std;

[Code] .....

View 8 Replies View Related

C :: Program Crashes And Returns Random Negative Numbers

Mar 1, 2014

I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.

Code:
/* Evan Wentz */
/* Pike - ET2560 */
#include <stdio.h>
#define MAX_ACCTS 100

int accounts [];
double balances [];

[Code] ....

I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...

View 6 Replies View Related

C++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C :: User Input - Inverting Odd Numbers

Jan 26, 2014

Now i got here a program that asks the user to input 2 numbers if the first inputed number is smaller than the second then show all even numbers from the range of the 1st inputed number till the 2nd inputed number, but if the first inputed number is greater than the second then display all odd numbers from the range of the 1st number till the 2nd.

now my question is how do i invert the odd numbers?(on the 2nd condition)

Code:
#include<stdio.h>
int main(void) {
int i,a,b,x;
printf("Enter two numbers");
printf("
First number:");

[Code] ......

View 4 Replies View Related

C++ :: Printing The First N Prime Numbers (user Input)

Jan 15, 2014

//Finding prime numbers
#include <iostream>
using namespace std;

[Code]....

/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.

View 1 Replies View Related

C++ :: Generate Random Number Between Two Numbers (User Input)

Jul 26, 2014

I am trying to generate a random number between two numbers that the user gives me.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void rand_int(const int &min, const int &max, int &val);

[Code] .....

View 3 Replies View Related

C++ :: How To Error Check If User Input Is Letters And Not Numbers

Jun 9, 2014

How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.

I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?

Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void OpenTheFile() {
ifstream inputFile;
string filename;
char letter;
int number;

[Code] .....

View 1 Replies View Related

C/C++ :: User Input Validation - Finding GCD And LCM Of Multiple Numbers

Oct 23, 2014

I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.

#include <stdio.h>
void bubble_sort(int numbers[], int len) {
int i, j;
int swapped;

[Code] .....

View 2 Replies View Related

C++ :: For Loop - Display Smallest And Largest Numbers From User Input

Jul 29, 2013

I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.

This is what I have ....

#include <iostream>
using namespace std;
int main() {
int amount;
int count;
int number = 0;
int smallest = 0;
int largest = 0;
cout << "Enter total numbers to process: ";

[Code] ....

View 4 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++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C++ :: User Input - Calculate Sum Of Only Positive Values While Ignoring Negative Numbers

Jun 19, 2014

So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.

View 4 Replies View Related

C++ :: Search User Input Number In Array Filled With Random Numbers

Nov 6, 2014

I need to create A program That makes a 12x10 Array Grid Filled With Random Numbers From 0-99.

Then I need To Allow The User To Input A Number Between 0-99 And Then The program will then search through the array and count how many of the users number there is inside the array.

Code:

#include <iostream>
using namespace std;
int main() {
int input;
int number;
int row=0;
int col=0;
int Array [12][10];

[Code] ....

View 1 Replies View Related

C++ :: User Input Two Numbers - Calculate Square Root Then Roots Are Added Up To Return Sum

Aug 23, 2014

I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.

#include<iostream>
#include<cmath>
float main(){
using namespace std;
float m1,m2,m3,m4,m5;

[Code] ....

View 4 Replies View Related

C++ :: How To Get Program Recognise User Input

Dec 8, 2013

I need the program to do a calculation after the user inputs 10 numbers . This is what I have tried so far:

int count;
float value, high,low, sum,average;
sum=0;
count=0;

input:
printf("Enter a number (enter negative value to finish program):
");
scanf_s("%f",&value);

[Code] ....

output:
average=sum/count;
if(count==10) {
printf("total values :%d
",count);
printf("The Highest value :%f
Lowest Value: %f
",high,low);
printf("The average of the values is:%f
",average);
}

View 3 Replies View Related

C++ :: Program That Accepts Two Input From User?

Dec 8, 2013

I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.

main.cpp
#include <iostream>
#include "newclass.h"
using namespace std;

[Code].....

View 5 Replies View Related

C++ :: Program That Will Allow A User To Input Their First Name Into A String

Feb 23, 2015

So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"

My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.

#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;

[code].....

View 7 Replies View Related

C++ :: Program That Accept Input For User ID

Oct 28, 2013

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.

View 3 Replies View Related

C++ :: Program Skips Over User Input?

Dec 6, 2014

I am so close to finishing this program of games, but I'm running into some issues while debugging it.

I've attached the google drive folder since there are several files (ignore the ones with [conflict], etc)...

First, I have the main menu using a switch to select the game. The default was set to exit. If initially when immediately opening the program you put in for say, a letter, it would exit like its supposed to. But if you went and played any of the games ], went back to the main screen, and entered a letter then, it would crash. I've put in a testing line to make sure that you enter a number, and not anything else.

Now however, if you play a game and then want to go back to the main menu, it will simply skip over waiting for your response and close the program. The same thing happens in the slot machine, I want to have it spin the slot machine by pressing enter, but it simply skips over the input, and I'm not sure why.

[URL] ....

View 2 Replies View Related

C++ :: How To Allow User Input To Exit The Program

Feb 20, 2013

I need to create a command where the user inputs a character and it'll exit out the program rather than executing any of the other code.

For example :

If I wanted to do like
char key;
if (key == D || key == d)
{
}

What would I need to put in between those brackets under the if statement to allow the user to enter the letter D and it would close out the program?

View 2 Replies View Related

C :: Program To Capitalize Every Other Word Of User Input

Feb 26, 2013

I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").

I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:

Code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
{
// get user input
printf("Type a sentence: ");
string s = GetString();

[Code] .....

The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.

View 2 Replies View Related

C++ :: Exit Two-threaded Program With User Input?

Sep 9, 2014

// clang++ -g -std=c++11 main.cpp -pthread
#include <iostream>
#include <thread>
#include <unistd.h>
void thread1(void) {
while(1)

[code]....

Thread 1 does some background work, and thread2 is waiting for the user's input. If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have. If I do detach on thread1 does thread1 ever terminate? If not, how to terminate it? Also, how do I check if it's terminated or not?

View 2 Replies View Related

C++ :: Create A Program That Will Prompt The User For Input?

Dec 28, 2014

I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.

View 19 Replies View Related







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