C++ :: How To Enter And Print X And Y Coordinates On One Line Separated By Comma
Nov 22, 2014
I'm trying to enter an 'x' and 'y' coordinate on only one line separated by a comma. But I keep getting a syntax error. Here are the lines of code I'm using. This has to be simple. What am I doing wrong with this code?
Code:
cout<< "Please enter the x and the y coordinates of the first point,"<<endl;
cout<< "use a comma to separate them. " <<endl<<endl;
cin>> "You entered: " >>x1>>",">> y1 >>"for the first point" >>endl;
View 7 Replies
ADVERTISEMENT
Dec 13, 2012
How to enter person's last name and first name separated by space and comma.
For example henry smith---
Output-->>smith,henry
View 2 Replies
View Related
Nov 9, 2013
I tried to read in a file that contain studentId(8 integer long) and GPA in the same line separated by a comma, but I couldn't. Example:
145453565, 4.0
34344443, 3.9
23454345, 3.4
12345678, 3.4
void studentRecord::loading(string filename) {
ifstream infile;
int studentId;
double GPA;
[Code] ....
View 3 Replies
View Related
Oct 16, 2012
I have been trying to read a comma separated .txt file into an array and print it to console in C++. The txt file consists of two columns of double type data. For some reason the program runs, but gives blank output in the console. I want to know if I am doing something wrong. So far this is what I have:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
int i=0;
double x[10];
double y[10];
string line;
[Code] .....
View 3 Replies
View Related
Jul 30, 2014
I just wrote a code that reads in a text file called "policies.txt" which looks like this:
Pol1 M N 20 100000 1 .04 99
Pol2 F S 30 100000 1 .05 99
Pol3 M S 72 750000 1 .03 99
Pol4 F N 45 1000000 1 .05 99
This works perfectly fine, but what if I want each element of the table to be separated by commas. For example:
Pol1,M,N,20,100000,1,.04,99
Pol2,F,S,30,100000,1,.05,99
Pol3,M,S,72,750000,1,.03,99
Pol4,F,N,45,1000000,1,.05,99
or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work? This is my code to reference.
double ratesmn[86] = {
#include "MaleNonSmoker.txt"
- 1
};
double ratesms[86] = {
#include "MaleSmoker.txt"
[Code] ....
View 4 Replies
View Related
Jul 7, 2013
I'm trying to read names separated by a comma using array.
For example, the expected input would look like the following:
Juila,Francisco
Adams,Wong
I know you can use getline function and set the delimiter to comma. So like ....
getline(cin, lastName, ','); getline(cin, firstName);
But the program only read the last name and ignore the firstname.
View 1 Replies
View Related
Jan 18, 2013
TinyGPS::TinyGPS()
: _time(GPS_INVALID_TIME)
, _date(GPS_INVALID_DATE)
, _latitude(GPS_INVALID_ANGLE)
[code]....
I am wondering about the constructor. I see there appears to be nothing inside of TinyGPS::TinyGPS() as far as parameters go and that that declaration is followed by a ":". First I'm wondering as to the meaning of the colon. As well with the variables defined after the ":" I see some "(0)" and I am wondering as well to the exact meaning of the "(0)". Are those variables being defined as parameters separated by ","?
View 2 Replies
View Related
Apr 18, 2013
I am attempting to read in a file that has 4128 sets of 21 numbers separated by commas and write it into an array. I now know that in order to use fseek, I have to make my array a character array, but I need my function to read in decimals (ex: 0.172635). I'm reading in
0.102598,0.000000,0.000000,0.000000,0.000000,0.307 793,0.000000,0.410391,0.102598,0.000000,0.102598,0 .102598,0.000000,0.000000,0.102598,0.102598,0.8207 83,0.000000,0.000000,0.000000,0.000000
and keep getting numbers like 48 49 50.
Code:
void CSread(char filename[100], char array[22], char array2[22], unsigned int arraysize)
{
char genename[32];
double temp = 0;
FILE *CSfile;
CSfile = fopen(filename, "r");
");
[code].....
View 8 Replies
View Related
Sep 16, 2013
I have prepared a file through the use of following code
Code:
fprintf(file2, "%i %i %i %i %i %i
",
msg_id,
msg_size,
msg_period,
msg_deadline,
msg_producer,
msg_comsumer
);
As one can see, this file has tab separated integer entries. The file is written correctly, let us call this file "msg.txt".
I face the problem when I read this file, using fgets as follows:
Code:
char singleMessage[100];
while( fgets(singleMessage, sizeof(singleMessage), file ) )
{
puts(singleMessage);
sscanf(singleMessage, "%i %i %i %i %i %i
",
&first, &second, &third, &fourth, &fifth, &sixth);
fprintf(stderr, "first: %d, second: %d, third: %d, fourth: %d, fifth: %d, sixth: %d
",
first, second, third, fourth, fifth, sixth);
}
but fgets only retrieves until the first, i.e, if the first line in the file reads:
788004425
fgets returns only 78.
Does it have to do with how the file was written in the first place.
View 1 Replies
View Related
Jan 16, 2013
I use the AS/400 warehouse system, and I need to be able to automate typing one letter in several different locations to speed things up.
My thoughts are:
1. Find out how to make a program that will determine x, y coordinates of mouseclicks, and then use software to use macros to change information.
2. Build a program that will complete a single process by repeating set mouse clicks and keystrokes.
We recieve HUGE transfers from a warehouse across the country, and have to change the first character of the name of bin locations - and after a few pages it gets VERY tedious.
View 4 Replies
View Related
Apr 21, 2013
Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :
10*9*8*7*6*5*4*3*2*1
i try to do it but it show me like this :
10*9*8*7*6*5*4*3*2*1*
how do i write to show me like the first one ?
View 10 Replies
View Related
Feb 18, 2015
Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.
For example, if the number is 2339 the program should print
9 *********
3 ***
3 ***
2 **
So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!
My code so far:
int main() {
int n;
printf("number? ");
scanf("%d", &n);
while (n > 0) {
printf("
%d
[Code]...
View 4 Replies
View Related
Sep 22, 2013
I want to make an object, which moves from x1,y1 to x2,y2 in a straight line, also make a sinus over the line (so the x,0 is the line itself, and cux,cury is the object. So the object will move as a sinus over the line. How do I do this in c++?
View 3 Replies
View Related
Mar 5, 2013
I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have
Code:
#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")
[code]....
View 1 Replies
View Related
Mar 12, 2013
Just working up for the google coding contest to start soon and have been practising some of the test questions however i make correct algorithms but my output is rejected because of the fact that my strings are printed on a new line so i wish to know a method to print strings using a printf statement or any other function on the same line ...
View 3 Replies
View Related
Mar 9, 2013
Actually the below program is for Dispersal Algorithm called Rabin-IDA; this algorithm divided the data into N pieces and then recombine it from M pieces (such that M<N).
Thus, the below program needs command line arguments,which entering by Project properties/Debugging. this argument is file name, where the program performing spitted the file into N files, and then recombine it from M divided files, and put it on another file which should also passing its name as argument .
Now my question is, How can i make this program enter the file name by keyboard??(i mean enter the files name by user from screen not as command line arguments)
The below code is just the main function of program, and the whole of it in this link (http://www.juancamilocorena.com/home/projects) Information Dispersal Algorithms Rabin-IDA
#include "include.h"
void __cdecl _tmain(int argc, TCHAR *argv[]) {
DWORD ini=GetTickCount();
try {
if( argc == 3 ) //recombine
[Code] .....
View 4 Replies
View Related
Mar 5, 2013
I think I need to use
Code:
while(input[0]!='
'){
scanf("%s", input)
printf("%s", pointerhere);
}
basically we were asked to make a program that will print everything before the user hits the enter button. we cannot use fgets and we have to use pointers here.
not sure what exactly to do. We were told not to use fgets cause it's so easy and we need to incorporate pointers in this project..
View 8 Replies
View Related
May 19, 2013
I have a program that uses class functions to enter and print out info. The problem is with the second function answers(). Here is the whole cpp file. In the answer function I need to use an exception to exit when its the end of an array. I could just be doing it wrong. I used try/catch originally but when I used it, it caught the exception but ended the whole program.
#include <iostream>
#include <cstdlib>
#include "answering_machine.h"
using namespace std;
void AnsweringMachine::init(){
numMessages = 0;
[Code] ......
View 6 Replies
View Related
Mar 10, 2013
Actually the below program is for Dispersal Algorithm called Rabin-IDA; this algorithm divided the data into N pieces and then recombine it from M pieces (such that M<N).
Thus, the below program needs command line arguments,which entering by Project properties/Debugging. this argument is file name, where the program performing spitted the file into N files, and then recombine it from M divided files, and put it on another file which should also passing its name as argument .
Now my question is, How can i make this program enter the file name by keyboard??(i mean enter the files name by user from screen not as command line arguments) ... In another word, How I can exchange ?
Code:
argc == 3
and
Code:
argc == 2
To enter file name ? i mean what i should do to in
Code:
rabin.split(argv[1])
To pass my file name by use keyboard not Project properties/Debugging?)
the below code is just the main function of program, and the whole of it in this link [URL] .... Information Dispersal Algorithms Rabin-IDA.
Code:
#include "include.h"
void __cdecl _tmain(int argc, TCHAR *argv[]) {
DWORD ini=GetTickCount();
try {
if( argc == 3 ) //recombine
[Code] ....
I know I should use getline() function but how exchange argv[] ?
View 1 Replies
View Related
Aug 8, 2014
How can I create in my C++ program so a user can paste a text and then choose a character on specific line and place?. The above thing isn't that important. I just want to place a character on a specific line and place.
I mean something like this:
Enter a character:
You choosed " / "
On which line do want the character?
You choosed "Line 1 and 2"
Where do you want the the to appear on the line? (left or right)
You choose left.
Results:
Line 1. / hello
Line 2. / hello
View 8 Replies
View Related
Oct 28, 2014
The code I have is below. Im able to print them all onto one line but I need to print 10 per line separated by commas and Im not sure how to do that ):
for (int i = 0; i < MAXVALUE; i++){
for (int j = 0; j < counts[i]; j++){
output << i << ",";
View 1 Replies
View Related
Dec 10, 2014
We need a program that takes three names ( first middle last ) and print it each one at a different line...
View 5 Replies
View Related
Aug 4, 2014
I try to learn string class, resolving some problem, but i have some dificulties.The is ok, but when i print the longest string it does'n print on the same line.I enter the number of string, after that i enter the first string until i introduced from keyboard "#" character. I enter the second string and so on.Look at these example :
For i = 3;
Text[0] : I learn class String#
Text[1] : I dont learn class String#
Text[2] : String#
It print me like that : Text[1] :
I dont learn class String More than that look at the next example :
For i = 3;
Text[0] : I learn class String#abcdef
Text[1] : I dont learn class String#
Text[2] : String#
You see that in the first sentence i have continue to introduce some characters after # character and look what is happened :
Text[1] : abcdef
I dont learn class String
#include<iostream>
#include<string>
using namespace std;
int main() {
string text[100], cuvant;
int i, j, m, lung = 0;
cout << "
[code]....
View 3 Replies
View Related
Jul 28, 2014
I am using C++ to write data into a (.ini)file. However, when I try to print the value '0A' I am getting '0D 0A'. (this is what I see when I copy the output to HexEdit). From what I can figure out, '0A' is the ascii for 'new line' so write function automatically adds the '0D' which is 'carriage return'. What I want is to print 0A alone. how can I do this?
Note: Windows it is working fine, but linux it is not working...
unsigned char arrRes[4];
int N = 10;
memcpy(arrRes,&N,4);
std::ofstream Output(LUT_OUTPUT_FILE_BINARY,std::ios_base::binary | std::ios_base::out);
Output.write((const char*)arrRes, 4);
here 10 means 0x0a but it is printing 0d,0a...
View 5 Replies
View Related
Sep 2, 2013
I'm having problems fully comprehending how to do this task (I'm only going to include my function code since that's the basis of my problem). How should I go about getting my vector to print off 12 items per line. Here's my current function.
void printVec(const vector<int>& v) {
for(unsigned i=0; i < 12;i++)
cout<<v[i]<<" "<<endl;
}
View 2 Replies
View Related
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related