C/C++ :: Use EOF To Terminate Inputting Data?

Mar 18, 2013

how to use EOF to terminate inputting data

View 1 Replies


ADVERTISEMENT

C/C++ :: Inputting Data Into Two-dimensional Array

Apr 19, 2014

So I have a two-dimensional array named temperatures[7][2] and I am trying to promt the user to input the highest temperatures for a 7 day period in the first column and the lowest temperatures in the second column. So far all I am getting when I test my code is the temperatures in the second column.

/*Intermediate23.cpp - This program inputs the highest and lowest temps. for seven days. It then displays the average high and low temps. and also diplays the highest temp. that's stored in the first column of the array and displays the lowest temp. stored in the second column of the array.*/

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//Declare array and variable
int temperatures[7][2] = {0};
int avg = 0;
int totalTemp = 0;

[Code] ....

View 4 Replies View Related

C :: Inputting Data From Multiple Lines Using Scanf?

Aug 1, 2013

How would I go about inputting data from multiple lines using scanf?

So far I have tried a loop and somehow checking for '' but can't seem to figure it out..

E.g I want to be able to scanf the ints below line by line and print them( if that makes sense) .

5 15 20 30 5 6
5 6 8 20 34
5 6 7
5 2
2 6 7 2 1 6

This is what i've tried so far, but am really lost!

Code:

int input;
while(scanf("%d", &input)){
printf("%d",input);
if(input == '
'){
continue;}}

View 13 Replies View Related

C :: How To Terminate A Function

Feb 17, 2013

How can I terminate a function?

View 3 Replies View Related

C++ :: Why System Cannot Terminate Itself

Nov 18, 2014

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

[Code].....

This is my code, when my pintrials = 0, my system cannot terminate but go through the option menu below.

View 1 Replies View Related

C++ :: Use Value 0 To Terminate Program

Mar 20, 2013

"Allow the user to enter an integer, between 1 to 9 only. You may use the value ‘0’ to terminate the program. Then display the output as follows:

Sample Run 1
Enter an integer (1-9):4
1
121
12321
1234321

Sample Run 2
Enter an integer (1-9): 20
You have entered an invalid entry, please try again.

Enter an integer (1-9): 0

(Try to use remark to explain function and process area)

View 3 Replies View Related

C++ :: How To Terminate While Loop With Newline

Apr 24, 2012

I am new to C++ and wrote some code here that is not working how I want it to:

Code:
int main() {
vector<string> distinct;
string parag;
typedef vector<string>::size_type vec_sz;
vec_sz size = distinct.size();

[Code] ....

Basically, if I run it, it takes a string, stores it in a vector string, and then outputs it to the screen as I hit enter. But then it waits for another string to be entered. How can I stop it waiting for new input after I hit enter? I tried comparing parag with and terminating there, but I am getting compiler error. I am using code::blocks.

View 2 Replies View Related

C++ :: Terminate Loop When Two Integers Between 1 To 100 Are Equal

Mar 21, 2013

creating a program using while that terminates the loop when two intergers any two between 1 to 100 are equal with each other

View 2 Replies View Related

C/C++ :: How To Null Terminate Unsigned Short

Jul 23, 2014

I've stored a binary pattern in what is interpreted as an unsigned short.

unsigned short byte_one = 128;

I've done some bitwise manipulation and want to store it back into an array, however, it needs to be null-terminated.

buf[1] = byte_one;

How do I null-terminate this?

View 3 Replies View Related

C++ :: Application Has Requested The Runtime To Terminate It In Unusual Way

Jan 13, 2015

this application has requested the runtime to terminate it in an unusual way. contact the application support team for more information!!!

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

[code].....

View 6 Replies View Related

C :: Skips Inputs Instead Of Inputting Last Name

Mar 2, 2014

it skips the input phase,, instead of inputting the last name it goes directly to the firstname then middle initail and street name are working fine but it skips the street name then goes to city and so on....

Code:

char l[50], f[50], m;char strtname[50], cty[50], cntry[50];
int strtnum, zp, i;
system("cls");
printf("Enter Last name:");
gets(l);
printf("
Enter First name:");
}

[code]....

View 3 Replies View Related

C++ :: Inputting Text From A File?

Mar 27, 2013

I have to write this program that is to store the name, address, id number, etc of a student. The data is supposed to be brought in through main and there will be multiple students. I'm not sure what commands I should use to bring it in.

EDIT: This will make more sense. In the .txt file the info will be written like

Name
Last name
Address
etc.

I need to input that and use that for the appropriate number of students.

View 1 Replies View Related

C++ ::  how To Combine A Function Call And Inputting A Value

Mar 15, 2014

We're working on classes in my programming class, and I have a question about function calls.

Bascially, I have all my set and get functions set up and ready to go.

I was wondering if it was possible to have the user input a variable while calling a function.

for example

cin >> getname();

the user inputs a value that gets passed into getname.

Or does it have to be something like

cin >> name;
getname(name);

mind you all, this isn't code from my program i'm just spitballing here.

View 4 Replies View Related

C/C++ :: Inputting True For A Boolean Variable?

Feb 7, 2014

My assignment : "Input the answer as the words true or false and put the user's answer in a boolean alphabetic variable."

My code:

bool T;
cout << "Type 'true' for lowercase or 'false' for uppercase";
cin >> T;
if (T == "true") {
cout << "Enter a whole number in decimal base: ";
cin >> dec;
cout.setf(ios::showbase);
cout << "Decimal " << dec << " to Hexadecimal with lowercase: " << setbase(16) << dec;
}

I'm not sure how to get 'true' as user-input as true for bool.

View 3 Replies View Related

Visual C++ :: Terminate A Thread When User Push Stop Button

Nov 16, 2012

I have a thread with a while(1) loop in it. When the user push the stop button I would like that thread to end.

I thought about creating a bool and checking its value periodically in the thread and when I push the stop button I change the value of the bool for that the thread breaks out of the loop and finishes.

View 5 Replies View Related

C++ :: Inputting Into Double-sized Vector Freezes?

Mar 27, 2013

Whenever the code reaches:

matrix[atoi(tmp[1].c_str())][atoi(tmp[2].c_str())] = strtod(tmp[3].c_str(), NULL);

The app just blocks. Could it be due to a lack of RAM (since its inside a massive loop and I'm currently using an old-ass pc with 1GB RAM) or is it bad programming? If I remove that line everything runs smoothly.

View 7 Replies View Related

C/C++ :: Printing Struct Array After Inputting Information?

Aug 28, 2014

I am doing a data structures program on C++ that is suposse to consist of declaring an array of size five for my credit card structure, that allows the user to input information of five diferent credit cards. I am having a problem with my program, because it runs but after I input the information of the credit card, it does not print out the values that I had input.I dont know where I went wrong with the code or if it is that my approach to solving it is wrong. My code is the following:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct TarjetaCredito

[code].....

View 2 Replies View Related

C++ :: Inputting TXT File Into 2 Parallel Arrays Via Void Function

Nov 10, 2014

I have a .txt file that I need to input into two parallel arrays. The first array needs to be on dimension and the second needs to be two dimensions.

This is a sample from the .txt file:

Australia62.762.163.359.7
Austria052.853.154.6
Belgium30.430.327.525.3
Canada61.356.257.754.5
Chile026.425.431.1
CzechRepublic038.327.325.2
Denmark65.067.162.355.0
Estonia51.732.929.834.3
Finland55.242.942.143.3
France35.728.330.228.8
Germany56.447.242.646.6
Greece30.326.925.013.1
Hungary032.521.818.6
Iceland068.271.666.0

this is what I have for code so far:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;
const int SIZE = 40;
const int COLUMN = 5;
void getData(ifstream& inf, string n[], double tstData[][COLUMN], int count);

[Code] .....

when I compile and run the code and have it display it does not read the first item into the 1-d array, instead it appears to read the 4th number from the left into the 1-d array and then into the second spot in the 2-d array, then again in its proper place and finally it has this number repeating through the rest of the arrays:

-92559631349317830000000000000000000000000000000000000000000.00 followed by the number 59.7 from the .txt and the long number again.

View 10 Replies View Related

C :: How To Terminate A Loop If User Inputs Blank Space In A String Or Press Enter

Jan 28, 2015

Code:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;

[Code]...

View 3 Replies View Related

C :: How To Stop User From Inputting Negative Number Into Unsigned Long

Feb 3, 2013

here's one more thing id like to do to make the input even better able to handle user error, but im not sure if its possible or at least easy. I need the function to return a large positive number. As of right now, it can handle users entering characters, but what if the user enters a negative number? is there a way to check to see if what is coming in is negative before the sign gets lost in conversion to unsigned"ness"?

Code:
unsigned long getNum(char prompt[80])
{
unsigned long darts;
printf("%s", prompt);
while((scanf("%lu", &darts)) != 1)
{
[code]....

View 3 Replies View Related

C :: Program To State User Chinese Zodiac And Horoscope Sign After Inputting Birthday

Mar 26, 2013

I am a beginner trying to write a program that would state a user's chinese zodiac and horoscope sign after inputing his or her birthday. I have been, however, having trouble getting the program to run correctly.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define CAPRICORN "G"
#define AQUARIUS "W"
#define PISCES "F"

[Code] ......

View 3 Replies View Related

C++ :: File Operations Inputting A File Into Program

Jul 28, 2014

I keep getting this error when trying to compile.

error C2440: 'initializing' : cannot convert from 'void' to 'std::basic_ifstream<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> Expressions of type void cannot be converted to other types

Here is my entire program:

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

[code].....

View 13 Replies View Related

C/C++ :: Find Max Number Entered By User And Terminate When Negative Number Entered

Jul 15, 2014

I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.

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

[Code] ....

View 9 Replies View Related

C :: Store Data In Binary File Then Use It To Find Inverse Of Matrix Form Of Data

Dec 6, 2013

I need to find inverse of a matrix data in binary file should be used to form matrix.its not finding inverse correctly rest is working good.

Code:
#include <stdio.h>
void createbin();
void display();
void inverse();
int main()
{
createbin();
display();
inverse();

[Code] ....

View 4 Replies View Related

C++ :: Read Byte Of Char Data And Convert It Into Text String Of Binary Data That Represents Hex Value

Dec 26, 2013

I am writing a program where I need to read a byte of char data and convert it into a text string of binary data that represents the hex value...

i.e. The char byte is 0x42 so I need a string that has 01000010 in it. I've written the following subroutine....

------------- My Subroutine ----------------------------------------------------------------------
void charbytetostring(char input, char *output){
int i, remainder;
char BASE=0x2;
int DIGITS=8;
char digitsArray[3] = "01";

[Code] ....

When I submitted the byte 0x42 to the subroutine, the subroutine returned to the output variable 01000010... Life is good.

The next byte that came in was 0x91. When I submit this to the subroutine I get garbage out.

I am using a debugger and stepped through the subroutine a line at a time. When I feed it 0x42 I get what I expect for all variables at all points in the execution.

When I submit 0x91 When the line remainder = input % BASE; gets executed the remainder variable gets set to 0xFFFF (I expected 1). Also, when the next line gets executed..

input = input / BASE; I get C9 where I expected to get 48.

My question is, are there data limits on what can be used with the mod (%) operator? Or am I doing something more fundamentally incorrect?

View 6 Replies View Related

C++ :: Add Data To Text Files Which Are Required To Store 3D Scan Data

Jul 10, 2013

I have written the following code to add data to text files which are required to store 3D scan data (I have to calculate the y-coordinate). My code seems to work except that it stops working when I want to create more than ten text files i.e. the directory I am trying to store them in will not hold any more than ten text files. Code is shown below.

#include <string>
#include <locale>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

[Code] ....

View 1 Replies View Related







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