C++ :: Effect On Output Of Program Of Different Numbers Input To Int Data Type Named

Mar 2, 2014

// this program gives random number output
#include <iostream>
#include <cstdlib>// contains function protype for rand
#include <iomanip>// for setw
using namespace std;

[code]....

what is the effect on output of program of different numbers input to the int data type named seed*/

View 1 Replies


ADVERTISEMENT

C++ :: How To Check For Data Type When Input Value Into Program

Apr 11, 2013

How would I check for proper data type when someone is to input a value into the program? Ex:

int i;
string a;
cout << "Enter a number: ";
cin >> i;
cout >> "Enter a string: ";
cin >> a;

How would you check to make sure that int i would be an actual number and not a letter like "a"?

View 4 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++ :: What Data Type To Treat Input As

Sep 3, 2013

I know that an int is usually 4 bytes, ranging from -2^31 to 2^31-1 for a signed int and 0 to 2^32-1 for an unsigned int. My question is simply, bit-wise (I know they are labelled in the code), how does it determine whether to show -2^31 or 2^32-1 if it was 11111111 11111111 11111111 11111111 in bits? Is there a 5th byte to tell the compiler what data type to treat the input as?

View 3 Replies View Related

C++ :: Finding Out Input Data Type?

Oct 15, 2013

I'm currently trying to solve a programming assignment and i got the logic of it, however i find it hard to implement.

What i need to do basically is fill an array with objects. Each object is a class that contains only one type of data. This means i can place int, double and string for example in one simple array.

However i can't figure out how to read data and then decide what it is. Even if i use templates once i call the function i have to give it a type, so getType<int> for example will not work with double or string.

I know about typeID and how to use it, i just can't figure out where to use it.

View 2 Replies View Related

C :: Which Data Type Have To Enter To Get 12 Digit Numbers

Jul 8, 2013

I've seen some threads that include the information about what data types one has to use usually to put a number of 12digit. But honestly speaking none of them works for me & it takes me a lot suffering about the data type. Even I've googled but I didn't get any specific result.

So, which data type I'd have to use to enter 12digit number.

I'm writing a code to find the largest prime factor of the number 600851475143

View 4 Replies View Related

C :: Program That Implements Audio Effect / Process Without Using External Libraries

Aug 1, 2013

The brief is to write a program that implements a musically-interesting or musically-useful audio effect/process in C without external libraries other than those prescribed (PortMedia/PortMIDI/PortSMF/PortAudio, Libsndfile).

View 6 Replies View Related

C++ :: Looping User Input For Specific Data Type

Apr 17, 2015

Here's my code so far:

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

[Code] ....

The code, when run, prompts the user to input an integer like this:

Code:

Day 1
Andy :>12
Bill :>7
Charlie :>15

Day 2
Andy :>5
Bill :>25
Charlie :>14
.
.
.
etc.

Ok, so the code prompts the user to enter an integer for each of the 3 persons and then increments the "Day" and so on... When the user enters a negative value (-1, -2, etc.), the loop is broken and the program ends. Alright, everything is hunky-dory so far. 2 things which I can't figure out.

1. when the user doesn't enter anything and just hits return, the cursor drops a line and is still awaiting an input but doesn't show the prompt "Andy :>", for example. How can I get it to repeat the last prompt when the user doesn't enter anything? Like:

Code:

Day 1
Andy :>
Andy :>
Andy :>12
Bill :>25
Charlie :>15
.
.
etc.

2. When the user enters a letter or a special character, the program blows up. How can I correct this?

I've tried changing the data type for the variable used for the input, tried using getline, get, etc. With my current beginner knowledge, I'm missing something. So how can I get this to work?

The program should allow only integers to be entered, while allowing a negative number to trigger the loop to break or the program to end, and while re-prompting the last person if the user entered an invalid input.

View 13 Replies View Related

C++ :: Simple Input / Output - Float Point Numbers

Apr 26, 2012

I have a simple input output problem using float point numbers and after the first input the program skips the other cin functions is there something that I did wrong? It compiles fine also.

Code:
#include <iostream>
#include <float.h>
using namespace std;
int main() {
int x;
int y;
int z;

[Code] .....

View 5 Replies View Related

C++ :: What Data Type That Will Read In Letters And Numbers Form Fstream

Sep 11, 2013

What data_type will read in a string of letters mixed with numbers using fstream :);

View 1 Replies View Related

C++ :: File Input / Output - Getting Highest And Lowest Number From A List Of 7 Numbers

Apr 16, 2013

I am currently confused on how to get the highest and lowest number from a list of 7 numbers for a File Output. Lets say i have 165 19 654 816 654 987 324. How would i get the 987 for the highest and the 19 as the lowest? Those numbers are not fixed numbers, i need to be able to input any combination of numbers and still be able to get the highest and lowest numbers from the list of 7 numbers.

View 1 Replies View Related

C++ :: Program That Reads In Ten Whole Numbers And Output Sum

Jan 23, 2014

Write a program that reads in ten whole numbers and that output the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the ten numbers just once each and the user can enter them in any order.

Your program should not ask the user to enter the positive numbers and the negative numbers separately. Assume the user will type integer numbers.

this is what i got but it wont run saying there is an error

#include<iostream>;
using namespace std;
int main() {
int count=0;
int num;
int positive=0;
int negative=0;

[Code] ....

View 5 Replies View Related

C++ :: Put Enumerated Data Type For Poker Program?

Aug 21, 2013

put enumerated data type in c++ for a poker program (specially for color and cardtype)?

Here are some codes:

//card.cpp
#include "cCard.h"
using namespace std;
cCard::cCard()

[Code]....

View 1 Replies View Related

C/C++ :: Can't Get Basic Input / Output Program To Work

Feb 29, 2012

im trying to write a program that prompts the user to enter three numbers and then prints them vertically (each on one line), first forward and then reversed. this is how the design should look:

enter three numbers: 1 43 54

your numbers fowards:

1
43
54

your numbers backwards:

54
43
1

this is what i have thus far when it comes to code....
   
#include <stdio>  
int main (void) {
// local declarations 
int a;
int b;
int c

[code].....

View 1 Replies View Related

C/C++ :: Program To Allow User Input And Output Perfect Number

Mar 11, 2014

The problem that I am having is that , the program outputs numbers that are perfect numbers and im not sure where i can add a statement to make it so that if it isn't a perfect number it doesn't output...

#include<iostream>// allows user input/output
#include<conio.h>
#include<fstream>//data file / result file
#include<iomanip>
#include<cmath> // math function
#define in_file "data.txt"
#define out_file "result.txt"

[Code] ....

View 3 Replies View Related

C++ :: Voter Program - Input Names And Votes / Output Who Won The Vote

Apr 27, 2013

In my class we were supposed to write a program from the book that inputted the names and votes and the program is supposed to spit out who won the vote. I did this then while i was reading the assignment from the instructor I noticed he wanted the information inputted from a TXT file instead of manually inputting it. I cannot seem to get it to work....

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define N 5
char names[N][20];
float votes[N];

[Code] ....

here is the txt file

Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800

View 2 Replies View Related

C++ :: Program Will Echo Letter (User Input) And Output Name Of The Day Of Week

Oct 21, 2012

Write a C++ program that does the following:

Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.

When the user enters a character, the program will echo the letter and output the name of the day of the week.

Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.

So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.

Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?

View 4 Replies View Related

C++ :: Traffic Control Program - Output Data At Specific Time

Oct 24, 2013

I was given an assignment to create a simple program for traffic control. How should i output data at a specific time, for e.g a driver approaches an intersection, the yellow light will flash indicating that he needs to slow down and then the red light to stop before taking a route. is there any function i can use to output red light a few seconds after yellow light.

View 10 Replies View Related

C :: Count Lines In Input And Display Output In Terminal When Program Executed After Compilation

Feb 4, 2013

Code:

#include <stdio.h>
main() {
int c, n1;
n1 = 0;
while ((c = getchar()) != EOF)
if (c == '')
++n1;
printf("%d", n1);
}

I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.

View 4 Replies View Related

C++ :: Multiple Of CSV File Used As Input / Extracting Data To A Output File - Getline Function

Jun 4, 2013

I have written a C++ program I have multiple of CSV file used as input, which I open one at a time and close it after extracting data to a output file which is the only file.

I run getline(inFile,line);
outFile << line << endl;

I run this code, and only part of it is goes to the output file I got, also have spacing randomly to specific file and inconsistent

But when I slower the code, like system("Pause") in the loop, I can get extract what I want perfectly....

Is my program running to fast, why getline would be skipping part of what things I want?

View 11 Replies View Related

C++ :: Program To Take Numbers From Input File?

Nov 12, 2013

I am trying to write a C program to take numbers from an input file (input.dat), calculate the sum and average of the numbers for each row, and display them in a form of table and in an output file (result.out).

Using these numbers in the input file.

-0.043200 -0.003471 0.000000
-0.040326 -0.004851 -0.000737
-0.018204 -0.004246 -0.001530
0.022249 0.008891 0.004870
0.074892 0.044237 0.032171
0.129600 0.100233 0.089016
0.174747 0.160100 0.161792
0.200242 0.199106 0.214417
0.174747 0.160100 0.161792

i have created the the file but i keep getting errors in the underlined area after the while!!!

#include <stdio.h>
int
main(void)
{

[Code].....

View 1 Replies View Related

C++ :: Program That Ask The Users To Input 4 Different Numbers

Nov 30, 2013

Make a program that will ask the users to input 4 different numbers. After the user’s input the program will display the formula on the next line. Next line would be the presentation of the formula which the variables were substituted by the inputs from the user, then returns the average of the numbers entered. **All inputs are integers except average which is float with two decimal places.

View 5 Replies View Related

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

C++ :: Program Save Input Data?

Feb 14, 2014

Can any C++ or C program save input data?

View 3 Replies View Related

C++ :: Input Validation - Program Cannot Accept Negative Numbers

Nov 12, 2014

#include <iostream>
#include <iomanip>
using namespace std;

// Function Prototype
void sortArray(int array[], int size);

[Code] ....

This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.

View 1 Replies View Related

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







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