C++ :: String Integer Value - Input / Output

Aug 14, 2013

Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.

Sample Run 1:
Input -> A111B222C
output -> 9

Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62

View 1 Replies


ADVERTISEMENT

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

View 3 Replies View Related

C/C++ :: Input Lowercase String / Output Uppercase String

Dec 3, 2014

write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use a character array to store the string.) Does this follow the criteria? This program is very similar to one I found on these forums but I have one problem, it outputs everything backwards! EX: dogs will output to SGOD. What I need to do to make it output correctly, I think it may have to do with getline?

#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main() {
char let[100];
cout << "Enter what you would like to be UPPERCASE: ";

[Code] ....

View 2 Replies View Related

C++ :: Input Integer To A String?

Oct 20, 2014

i wanna put an integer into a string for example:

Code:
string name;
int num=8;
name= "George"
//

I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();

View 7 Replies View Related

C++ :: String Input AND Output To File

Sep 15, 2013

I'm trying to write a simple program that will prompt for a string typed in by keyboard and save it to a file. I've tried lots of variations and this is just the latest version.

//Prompt for a string input by keyboard and save it to a file

#include<iostream>
#include<fstream>
#include <string
using namespace std;

[Code] .....

View 2 Replies View Related

C++ :: Input Integer Then Output Both Individual Digits Of The Number And Sum Of Digits

Oct 11, 2014

My problem needs to prompt the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. An example would be entering 8030 and it spits out 8 0 3 0 as well as 8+0+3+0=11 and it needs to work with negative numbers.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int base;

[Code] ....

Now I don't know if any of this is right a hint my professor gave us is that to get the fourth digit you would do base mod 10 and to get the first digit you do base divided 1000...

Code:

{
int power;
int counter=0;
int value=1;
cout << "Enter the power of 10 you want: ";

[Code] ....

View 2 Replies View Related

C++ :: Converting User Input Int To String Output?

Apr 22, 2014

I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.

Code below:

#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
int convet(){
cout<<"Enter a number to convert to string "; cin>>num;

[code]....

View 2 Replies View Related

C/C++ :: Converting Uesr Input Int To String Output

Apr 22, 2014

I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.

Code below.

#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;

[Code] ....

View 5 Replies View Related

C++ :: Input With String Statement - Output Result With HTML Tags To Populate Web Page

May 3, 2013

I'm working on a CGI application. I'm trying to test my input with a switch statement and output the result with html tags to populate a web page. From within the switch, I've coded as follows:

HTML Code:
switch(mFunc) {
case 0:
cout << "<p><b>YOU ENTERED THE FOLLOWING TO BE CALCULATED:</b></p>" "<h2>"<< number1 <<"+" << number2 << "</h2>" << endl;
break;
case 1:
cout << "You've entered" << number1 <<"-" << number2 << "to be evaluated" << endl;
break;

I know that I'll need to put this in an html body with a content type as such:

HTML Code:
cout << "Content-type: text/html
";
cout << "<html><body>
";

Am I able to do that directly inside of the switch statement?

View 11 Replies View Related

C/C++ :: Converting 8-byte Integer To String Based Integer

Oct 15, 2014

Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.

Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}

I wrote:

#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';

[Code] ....

0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?

View 4 Replies View Related

C :: Output Smallest Integer Entered - Loops / Function

Oct 22, 2014

I am trying to find a way to put a getSmallest function in here so that it will output smallest integer entered. If it is just an arbitrary amount of #'s and I don't know what will be entered I am confused. Both on how to do it and how to link my function to my loop.

Code:
/* Prompts user and gets integer numbers from keyboard, one number at a time. Ends program when 99999 entered. and displays various results.
Written by:
Date: 10/20/14
*/
#include <stdio.h>
#include <stdlib.h>

[Code] .....

Could I take this and just replace all variables a, b, and c with getNumber, where would I link/declare smallest?

Code:
/* ==================== smallest ======================
This function returns the smallest of 3 integers.
Pre given 3 integers
Post the smallest integer returned
*/
int smallest (int a, int b, int c) {

[Code] ......

View 1 Replies View Related

C++ :: How To Check If Input Is Integer

Jan 15, 2013

I have an assignment to do..i have done it..but i need to do one more thing. Things sound like this: user inputs 6 integers program needs to check them if there are integer if not it has to output a message for the user if the input is integer it has to go further and work with the input. I have used this structure :

if ( ! ( cin >> temp ) ) {
cout<<"Input is not integer.This program will end ! "<<endl<<endl<<endl;
system("pause");
return 0;
}

Where I declared temp as being int since i started, the problem is after it gets the last input still waits for an input i will attach the source code if needed.

View 3 Replies View Related

C :: Check If Input Is Integer Using Only Loops?

Nov 3, 2013

I have a homework that needs to verify if the input of the user is an integer using only loops no if statements Here's the problem:

A program is required that prompts the user for a number. The program will then print a series of asterisks to represent the number. If the user enters a number less than 1, the program stops. For example:

Enter a number: 5
*****
Enter a number: 3
***
Enter a number: 9
*********
Enter a number: 0

All user input must be validated:
- Check for non-numeric input when reading numeric input
- Check that values entered are within the expected range for their purpose, or in range based on the requirements statement

View 10 Replies View Related

Visual C++ :: Check If Input Is Integer Or Not

Jun 20, 2014

I have been trying to make a very simply programme that checks if the inputted information is an integer or not (i.e: that it contains no other characters).

I have tried using the isdigit function (but this only works for single characters). I have tried cin.clear, cin.ignore (1000) but this doesn't work either..

Any effective way to check if x in the following programme has been entered correctly

#include <iostream>
using namespace std;
int main() {
cout << "Please enter an integer (positive or negative)" << endl;
int x;
cin >> x;
HERE I WOULD LIKE CODE TO CHECK IF THE USERS INPUT IS VALID
}

View 2 Replies View Related

C :: If Put WRONG Input For INTEGER / Program Will Restart

Feb 15, 2015

I have a question about my program.. I would like to make a program that if you put "ABC" on INT, the program will restart again... below are my coding...but it not works..if i put ABC on INT, the "Invalid Mark.. please re-insert mark :" will repeat, repeat and repeat infinitely...

Code:

#include <stdio.h>
void calcul() {int mark;
char * grade;
if (!(scanf("%d",&mark))){printf("
}

[code]....

View 7 Replies View Related

C/C++ :: Input Float And Integer And Save It To Txt File

Mar 20, 2014

i am writing a program that requires me to write am input a float and an integer and save it to a txt file. When i try to compile my code i get an error "assignment from incompatible data type". ?

int *intconstant;
float *floatconstant;
int *value;
struct FILE *infileptr, *outfileptr;
infileptr = fopen("/home/brinkmann.brendon/assign14data.txt", "r");
outfileptr = fopen("/home/brinkmann.brendon/assign14report.txt", "w");

[Code]...

View 14 Replies View Related

C++ :: Making Diamond Out Of Asterisks Based On Given Odd Integer Input

Sep 6, 2014

I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.

Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>

using namespace std;
int _tmain(int argc, _TCHAR* argv[]){

[Code] ....

View 2 Replies View Related

C++ :: Separate Input Integer Into Its Individual Digits And Print

Apr 18, 2013

Write a full C++ program that inputs three-digit integer, separates the integer into its individual digits and prints the digits separated from one another. For example, if the user types 549, the program should print;

5 4 9

View 5 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++ :: How To Stop Floating Point Input Into Integer Variable

Mar 27, 2014

I am trying to make sure no floating point numbers can be input at any time in my roulette program. My code is too long to put in one post so I shall piece it out

#include <iostream>
#include <iomanip>
#include <random>
#include <cstdlib>
#include <ctime>
using namespace std;
// structure of arrays to pass to functions

[Code] .....

View 12 Replies View Related

C++ :: How To Stop Input Process When Five Negative Integer Entered

Jul 25, 2014

int a[20],x;
for(x=0; x<20; x++)
{

[Code]....

This should be the output

Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: -1
Input: -1
Input: -1
Input: 1
Input: -1
Input: 1
Input: -1

Stop!

View 5 Replies View Related

C/C++ :: Find Sum Of Prime Factors Of User Input Integer

Sep 16, 2014

As an assignment for school , I've to write a program to find the sum prime factors of a user input integer.

E.g. 20 = 2 x 2 x 5 , Sum = 2 + 2 + 5 = 9
E.g. 10 = 2 x 5 , Sum = 2 + 5 = 7

My method for finding the result is as follows :

- Divide the number by increasing values if int i , starting from i=2.

- Once I get a value of i that can divide the number without giving me a remainder , I add this value of i to int sum and divide the number by i.

- I will repeat this process until the user input value is equal to 1.

My code is as shown:

#include<stdio.h>
int primecheck(int n); // Function to check if i is prime
int primesum(int n); // Function to sum the values of i that are prime
int main(void) {
int n;
int sum;
printf("Enter a number (> 1): "); //Prompting and scanning user input ,n
scanf("%d",&n);
sum = primesum(n);

[Code] .....

But for some reason I keep getting an incorrect result, it's as if it is missing out the last factor for each case.

Eg. 20 = 2 x 2 x 5 , the result I get is 4 , which is 2+2
Eg. 40 = 2 x 2 x 2 x 5 , the result I get is 6 , which is 2+2+2;

I've looked through my code numerous times.

View 7 Replies View Related

C :: Redirecting Input And Output

Sep 14, 2013

I have this code:

Code:

#include <stdio.h> //printf
#include <stdlib.h> //exit
#include <unistd.h> //fork
#include <sys/types.h> //pid_t
#include <sys/wait.h> //waitpid
}

[code]....

I would like to, when running cat, send in some data like "testing" to its stdin, and then catch the output of stdout, and put it into a character array variable.Currently the parent stalls till the child is done.I imagine the parent has to some how detect that the child executed 'cat', and then send in input to stdin?Then somehow detect that 'cat' is done executing, and read the output from stdout? I have looked around and found "dup2", but I don't understand how to send in and get data to the child from the parent, especially since the "file descriptors" is not pointing to any files in the first place..

View 4 Replies View Related

C++ :: Audio Input / Output?

Feb 5, 2015

So I have a project in which I am processing audio signals in real-time. I want to create a class to do this using the ASIO driver. I don't want to use a cross platform library nor do I want to use windows API as it is very slow.

View 2 Replies View Related

C/C++ :: Console Input / Output?

Sep 7, 2014

I'm trying to write something that when a user is at the command line, the user can type and it displays of list of commands the user can use to run the application.

View 14 Replies View Related

C++ :: Zero And Output The Input With A Setprecision Of 2

Mar 31, 2013

I have a program that needs to output the input with a setprecision of 2 but when it outputs 0, it has to be "0", not "0.00"

How will I go about that?

Here is my code:

void PrintAllSales(double sales[][SLSPRDT]) {
cout << fixed << showpoint << setprecision(2) << endl;
cout << "ALL SALES
";
WriteLine('=', 63);

[Code] .....

And here is how it comes out:

1234
ALL SALES
===============================================================
Product # | 1 | 2 | 3 |
Salesperson 1 | 2000.00 | 0.00 | 299.00 |
Salesperson 2 | 0.00 | 2543.98 | 95.99 |
Salesperson 3 | 0.00 | 0.00 | 19.99 |
Salesperson 4 | 0.00 | 3854.75 | 0.00 |

But it should be like this:

1234
ALL SALES
===============================================================
Product # | 1 | 2 | 3 |
Salesperson 1 | 2000.00 | 0 | 299.00 |
Salesperson 2 | 0 | 2543.98 | 95.99 |
Salesperson 3 | 0 | 0 | 19.99 |
Salesperson 4 | 0 | 3854.75 | 0 |

View 7 Replies View Related







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