C/C++ :: Use EOF To Terminate Inputting Data?
Mar 18, 2013how to use EOF to terminate inputting data
View 1 Replieshow to use EOF to terminate inputting data
View 1 RepliesSo 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] ....
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;}}
How can I terminate a function?
View 3 Replies View Related#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.
"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)
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.
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 RelatedI'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?
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].....
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]....
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.
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.
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.
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.
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.
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].....
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.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
int main(void) {
int i;
char *str;
int len = 1;
[Code]...
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]....
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] ......
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].....
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] ....
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] ....
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?
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] ....