C++ :: Create Program That Lists Off Each Digit Of Integer?

Mar 20, 2014

I need to create a program that lists off each digit of an integer and then display the sum off all the digits in that integer. I know that sepereatly the sum function i wrote works. But the first part which i try to list off the digits work but in reverse order which i dont know how to correct. and for some reason that i cant figure out this is affecting the sum output.

#include <iostream>
using namespace std;
int digcount (int x) {;

[Code]....

View 5 Replies


ADVERTISEMENT

C :: How Program Works If Integer Is More Than One Digit

Mar 15, 2013

Assignment: Take an integer keyed in from the terminal and extract and display each digit of the integer in English. Ex. 932 --> nine three two

Code:

/*This program takes an integer keyed in from the terminal and extracts and displays each digit of the integer in English.*/
#include<stdio.h>
int main(void)
{
//DECLARE VARIABLES
int num;
}

[code]....

I don't know how the program works if the integer is more than one digit.

View 1 Replies View Related

C :: Program That Displays Each Digit Of Integer In English - Zeros Won't Display

Apr 24, 2014

I'm new to C programming and in my first computer science class. Our assignment was to write a program that displays each digit of an integer in English. I wrote the following but cannot figure out why it won't display zeros. When I execute and type in the number 1,000, I get "zero."

Code:
#include <stdio.h>
int main (void)
{
int x, y = 0;
printf ("This program displays each digit of an integer in English.

[Code] ....

View 5 Replies View Related

C/C++ :: Program Takes Integer Input And Displays Each Digit On New Line From Right To Left

Jan 23, 2015

I'm trying to create a program that takes an integer input and displays each digit on a new line from right to left.

An example of this would be:

Enter an integer: 657
Digit (1): 7
Digit (2): 5
Digit (3): 6

So far I have this:

#include <stdio.h>
#include <math.h>
int main() {
int i, input, output;
printf("Enter an integer: ");
scanf("%d", &input);
if(input == 0)
printf("Digit (1): 0");

[Code] ....

It works perfectly fine, but I just learned that I am not allowed to use the #include <math.h> so I have to take out floor, log, and pow.

I'm pretty sure I have to do some sort of while or for loop to get the results, but how to do it.

View 6 Replies View Related

C++ :: Create Program That Has User Input 5 Digit Number?

Mar 9, 2013

Im trying to create a program that has the user input a 5 digit number. If it's between 10000 & 99999, it will do one thing..(just saying 'yes' for now. Outside those numbers will prompt the user to input again. However, if the user inputs the exact digits 76087, it should display 'term'.

This current code is displaying 'term' whenever the user inputs the 5 digits.

Code:

#include <iostream>
using namespace std;
int main() {
int pin;
cout << "Welcome to Movie Food
Enter your 5-digit pin code: " ;

[code]....

View 14 Replies View Related

C++ :: Repeated Digit In Integer

Oct 19, 2013

this code :

#include <cstdlib>
#include <iostream>
#define TRUE 1
#define FALSE 0
using namespace std;
typedef int Bool;

[Code] ....

Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.

so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????

View 3 Replies View Related

C++ :: Read (three Digit) Integer Representing Value To Be Encrypted

Nov 3, 2013

I have been working on some C++ code that doesn't seem to be going right. I'm wanting it to read a (three-digit) integer representing the value to be encrypted, a (one-digit) integer representing the encryption key, encrypt the value and print the encrypted value. The encrypting method used is that each digit in the given number is replaced by ((the sum of that digit plus key) modulo 10) then the first and last “encrypted” digits are swapped.

For example, if the number entered was 216 and the key given was 7, after applying the encryption procedure described the first digit (2) would become 9, the middle digit (1) would become 8 and the last digit (6) would become 3. The first and last encrypted digits are then swapped. The program displays the encrypted number: that is 389 in this case.

#include <iostream>
using namespace std;
int main() {
int isolateDigits();
int replaceDigits();
int swapDigit1withDigit3();

[Code] ....

View 1 Replies View Related

C++ :: Return The Digit At User Specified Index Of Integer

Oct 10, 2014

Return the digit at the user specified index of an integer. If the integer has n digits and the index is NOT in the range 0 <=index <n return -1 Start the digit numbering at 0. Example, if user input is 4 (index) and the integer equals 123456790 the return value for the function is 5 (start index at 0) ; if user input is 40 (index) and the integer equals 123456790 the return value for the function is -1

#include <iostream>
#include <istream>
#include <cstdlib>
#include <cassert>
#include <string>
using namespace std;
int getIndex(int, int);

[Code] .....

View 4 Replies View Related

C :: Create A Program That Asks User To Input Integer Lengths Of Three Sides Of A Triangle

Sep 6, 2013

C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[]){
int SideA;
int SideB;
int SideC;
}

[code]....

View 14 Replies View Related

C++ :: Input Validation For 5-digit PIN Number Read From Integer

Oct 22, 2014

The problem states that i need to accept any pin number between "00000" and "99999". I need to read the PIN the user enters as an integer. The problem is that if the PIN is read as an integer, the PIN "01111" will be "1111" which is invalid and the pin "00001" would be read as "1" which is also invalid. How would I go about fixing this problem for PIN numbers that start with a "0"? Again I cannot read the PIN as a char array or string.

View 2 Replies View Related

C++ :: Convert Positive Integer Into Its English Name Equivalent To Digit?

Jul 13, 2014

convert a positive integer code into its english name equivalent for digit. A valid code is of size between four (4) to six (6) digits inclusive. A zero is not allowed in the code.

example : if the input is 234056 the output is : INVALID CODE (PRESENCE OF ZERO)
if the input is 23456 the output is : TWO THREE FOUR FIVE SIX
if the input is 9349 the output is : NINE THREE FOUR NINE
if the input is 245 the output is : INVALID CODE (3 DIGITS)
if the input is 2344567 the output is : INVALID CODE (7 DIGITS)

step 1 : input code
step 2 : count the number of digits in the code
step 3 : if there is a zero in the code, "INVALID CODE (PRESENCE OF ZERO)" go to step 4
step 4 : if number of digits is mode or equal than 4 and less or equal than 6, go to step 5 else display the following message "INVALID CODE (<number of digits> DIGITS)
step 5 : call a function called digit_name to convert each digit into its
equivalent english name. display the result
step 6 : print the digits in reverse order
eg; if input is 13453, reverse order is 35431

View 8 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C/C++ :: Swap A Digit From A Number With Another Digit Using Function

Oct 26, 2014

Write a function which will take 3 arguments. The function needs to return a new number which is formed by replacing the digit on a given position in the number with a digit which is carried as an argument (the position in the number is counted from right to left, starting with one). Write a main program which will print the newly formed number.

Examples:
A function call of 2376, 3 and 5 should return the number 2576
A function call of 123456, 4 and 9 should return the number 129456

What I succeeded to do so far:
Figure out the logic for swapping the digit and write working code for it (in the main function).

What I failed to do so far:
Write a function which will return the desired result.

What is my problem:
I tried writing a function to do this, but as you see from my calculations, my result is divided in 3 parts. I don't know how to return more variables from a function.

Code:

#include <stdio.h>
int main() {
int inputNumber, swapPosition, swapDigit;
scanf("%d%d%d", &inputNumber, &swapPosition, &swapDigit);
int i, numberPart1 = inputNumber;
for (i = 1; i <= swapPosition; i++)

[Code] ...

View 8 Replies View Related

C :: Program That Will Generate But Not Display Three-digit Target Number

Oct 6, 2014

Write a program that will generate, but not display, a three-digit "target" number that has three distinct digits. (Hint: use random number generator.) Then, input a maximum of ten user guesses and for each guess, output the number of hits and matches in the guess. Stop when the user guesses the number or runs out of guesses. For example, if the target is 427, the guess 207 has one hit (7) and one match (2).

View 8 Replies View Related

C/C++ :: How To Get Rid Of Lists And Vectors In Program

Apr 16, 2015

I want to get ride off lists and vectors in this program i also don't want to use classes, just want to use strings functions and structures...

#include <iostream>
#include <string>
#include <list>
using namespace std;
struct contact {
string name;
int studentiD;

[Code] ....

View 1 Replies View Related

C++ :: Program To Sort Lists?

Aug 12, 2014

What I want to create is a program that sorts through a huge list (millions of lines).

I want it to get rid of any line that contains a word that isn't in an English dictionary.

Example list:

00sdfdsf
ahdadsg
angel
ksjflsjdf
green
green000
carrot

and it would go through millions like that, giving me only:

angel
green
carrot

as my new list.

How could I go about this? What programs would I need? And at the very least how can I remove unwanted things like numbers, double letters, underscores etc.?

View 3 Replies View Related

C++ :: Program To Display All Fibonacci Numbers And 21st Digit Using Array

Mar 7, 2013

Create a program that display all the fibonacci numbers and display the 21st digit using array.

Here's my code:

#include <iostream>
using namespace std;
int main () {
cout<<" This program shows a series of fibonacci numbers
"<<endl;

[Code] ....

View 2 Replies View Related

C++ :: Create A Function With Integer Number As Parameter

Jun 20, 2013

I must create a function with a integer number as parameterThis function use the parameter for a loop...example

n = 1
output
1
2
3

n = 2
1,1
1,2
1,3
2,1
2,2
2,3
3,1
3,2
3,3

View 1 Replies View Related

C++ :: Create Single Integer Number From Four Integers

Mar 1, 2014

Write a program that reads four integers from a file ‘input.txt’.

The program will then create a single integer number from the four integers. The output of the program will be the single number and single number + 600.

#include <iostream>
using namespace std;
int main () {
int number , a;
cout<<"enter en integer number";
cin>>number;
cout<<"add 600 to the number"
cin>>a=number+600;
return 0;
}

View 5 Replies View Related

C++ :: Create New Data Type To Store Big Integer?

Oct 17, 2014

i need to create a new integer data type called BigInt to store a big big integer, which includes Dint(8 bytes) and Qint(16 bytes)

here is the hint/

typedef struct BigInt {
Int data[2];
}

How can i "scanf" and "printf" them????

void ScanBigInt(const char *format, BigInt &x)
if format is “%dd” -> input Dint, if format is “%qd”--> input Qint
void PrintBigInt(const char *format, BigInt x)

View 3 Replies View Related

C :: Create Array Of Integer - Function Call In Main

Feb 2, 2015

I'm writing code to create an array of integer and let user input choice to display, replace, add new element, etc.I created a header file in the header file there's a function:

Code:

int display_one_element(int* array, int num_of_elements, int position) {
if(num_of_elements < position || position < 0) {
printf("Position out of bound.
");
return 1;
}
return array[position-1];
}

in main I write a function call:

Code:

display_one_element(array, *p_num_elements, position);

My code seems to work fine but there's an error message right next to my function call:
1.too many arguments provided to function like macro invocation
2.Expression result unused

I tried to move the function from header file to c source file. but other functions in the header file works fine and this doesn't work with the error message.

View 3 Replies View Related

C++ :: Create Appropriate Word Form Of Any Positive Integer Up To 999999

Feb 17, 2013

My question is are there various ways that I can approach this program. I.e. do I have to use switch statements?

/*
NumToTxt
Creates the appropriate word form of any positive integer up to 999999
*/

#include <iostream>
using namespace std;
//represents the largest array size for the user entered number
const int MAXNUMARRAY = 6;
/*represents the largest number that can be entered + 1. Used to calculate the first number used to truncate the user
entered number and to display an error message to the user that tells the user the largest number that the program will
accept. */
const int BIGGESTNUMBER = 1000000;

[Code] .....

View 1 Replies View Related

C/C++ :: Dating Service Program Using Text File And Linked Lists

Jun 16, 2013

I'm new to programming, and I'm working on my second c++ program right now. Its a dating service where you read data from an input .txt file and store into a linked list, so then you can search, and modify the data. The text file is in this format:

M Dr.Gregory House,237-8732 7 Vicodin,Guitar,Piano,Motorcycles,Television,Food,W hiteboards.endl; (all on a single line).

First, is the sex (M or F), then the person's name, phone number, number of interests, then a list of their interests (with commas between each one, and a period at the end.) and then if they have a match you put their name there and put endl; after.

The main problem I'm having is setting up the link list, how to get it to read those as variables in the text, I know you have to use delimiters, but I can't quite figure out how to use them. You also have to keep two lists, one for males, and one for females in the output file. How do I do this? Is that a double linked list?

Here is the code so far (I know it isn't much..)

#include <iostream>
#include <fstream>
#include <string>
#include <limits>
#include <cstring>  
using namespace std;  
//Functions
void echoPrint();

[Code] .....

View 2 Replies View Related

C/C++ :: Convert Infix To Postfix Using Linked Lists And Stacks - Program Stop Working After 1st Call

Sep 28, 2014

I was given a task to convert infix to post fix using both linked lists and stacks in the code so this is what i have written but the problem is it is giving me same error at three different places "missing function header(old style format?)

#include <iostream>
#include <string>
using namespace std;
const int size = 100;
class stack{
private: // Declare a structure for the list

[Code] ....

View 12 Replies View Related

C :: Get 20 Integer Type Value In Program

Feb 5, 2013

I am trying to send 0x20 from arduino and get the hex in c program on the pc iam using RS-232 for Linux and Windows lirary for rs232 communication and when i send 0x20 i get 28ef30 i dont know why.. but i want to get 20 integer type value in c program the code that i use in c is

Code:

n = PollComport(cport_nr, buf, 4095);
if(n > 0)
{
buf[n] = 0; /* always put a "null" at the end of a string! */
}

[code]....

View 8 Replies View Related

C :: Program That Adds All Digits Of Integer

May 5, 2013

Just wanted to share a program I made. It was the answer to one of the end chapter exercises in the C programming book I'm using, asking the reader to create a program that adds all the digits of an integer.

Code:

/* Program to calculate the sum of the digits in an integer */
#include <stdio.h>
int main () {
int number, right_digit, sum = 0;

[code]....

View 7 Replies View Related







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