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
ADVERTISEMENT
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
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
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
View Related
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
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
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
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
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
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
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
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
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
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
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
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 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
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
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
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
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
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
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
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
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
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