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
ADVERTISEMENT
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
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
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
Sep 11, 2012
I have a project, a montly paycheck. So it checks the monthly paycheck of each employees. but my problem there is how to add a new employee when u are a user or in the output of program?
View 2 Replies
View Related
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
View Related
Jul 17, 2013
How to structure the input of one .dat file and outputting into another one. I have to loop through a file structured "doe, john, 1500", check for errors and then increase the mp by 50. You also have to do this through using a person class too. I think I need to use a while loop to go to eof and use getline to input correctly, but im not sure how to structure it.
Data file:
Horowitz,Jake,1200.24
Flabitz,Bubba,1712.38
Blackwell,Sharon,1872.93
Molerat,Rufus,501.00
Goodall,Jane,1567.43
Sommerset,William,1359.57
[Code] ......
View 4 Replies
View Related
Sep 22, 2014
for our school project, we have to make a program which involves three students and the prices each of them paid for the meals. The program has to calculate how much each of the students has to pay/receive to/from the others. Most of it, we got from our teacher. The error we are getting is that we have to 'take care of the input/output order'. So if you type in the names/numbers of the students in a different way, so for example if you type first number 1, then 0, then 2 and 0 and 1 have to pay money to number 2, number 0 has to be in front of 1. Our output is that number 1 is in front of number 0.
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
[Code].....
View 1 Replies
View Related
Jul 30, 2014
I'm learning C++. Is there some way to make program function on input from a port like usb port and can I send bits through the port? For example A usb cable connected to a circuit. I press a button and an AND gate on the circuit gets activated by a bit from the usb port and a fan in the room turns on.
View 1 Replies
View Related
Jul 24, 2014
I'm using getline, and stringstream to assign an input to a value. How to do something similar with a random output.
//Battle with Samer
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <cstdlib>
using namespace std;
const char* PokemonSamer[6] = {
"Charizard", "Umbreon", "Mew", "Arcanine", "Espurr", "Luxaray"
[Code] ....
When I run <PokemonSamer[rand() % 6]>, I want to be able to save whatever that output may be, and save it to <string Samer>. Is this possible?
View 6 Replies
View Related
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
Apr 25, 2013
I want to create a function that will accept input from the user and return the input, to be used for further calculation. I know how to accept and return with integers as parameters , but how do i do it with arrays?
Suppose there is an array of numbers arr[]. Now, i want a function that accepts the input from the user, and return the array for further manipulation.
For example, if the array is arr[5], then i should call a function and accept the values from the user. Then, i should return the imputed values and print the same. How can i do this.
View 3 Replies
View Related
May 2, 2014
Write a program that opens two text files (input1.txt and input2.txt) for input and one for output (output.txt). The program should merge the two input files in the output files. While doing the merge, it will read one line from input1.txt and one line from input2.txt and write those in the output file one after other. Then it will read the next line from input1.txt and next line from input2.txt and write them one after other in the output file.
This is my code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ofstream myproject;
myproject.open("input1.txt");
[Code] .....
I need to:
1. how to get the second line in the input1.txt file and so on.
2. After the writing in output.txt, count the number of lines in output.txt.
3. write the number of times term ‘line’ appears in output.txt file.
View 3 Replies
View Related
Mar 4, 2014
Alright, so to better myself with network logic I've decided to make a small net game.
I need to input commands to the console as well as output status updates at the same time. I'd prefer to write a gui interface for that, but I'd rather work with WinAPI as little as possible (I mean, look at the way it's designed...).
I'd like to do this with standard operations, limiting dependencies is a must for me.
View 6 Replies
View Related
Feb 6, 2015
Ok so This is what the output of the program should be.
enter the count of input integers: 1
The count of the integers must be two or more. Please enter a valid number : 3
Enter integer #1 : 2
Enter integer #2 : -1
Enter integer #3:5
The positive numbers entered and their squares are:
2 4
5 25
My Code :
//header files
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
[Code].....
View 6 Replies
View Related
Dec 24, 2014
#include <iostream>
using namespace std;
class Date {
private:
int month, day, year;
public:
// class constructors can be overloaded
Date(int m, int d, int y) {
[Code] ....
Actually ,I'm not sure whether my understanding of operator>> function is correct. Here is my understanding of operator>> function.....
operator>> function takes Date object as argument from main function and it reads data from the console using istream(This is all I know about istream) into the new Date object which is created by operator>> function..
This is all I know about operator>> function...I really don't know why it has to return istream reference(I know the return type is istream, but other than that ? I want to know why operator>> function creates new Date object ? It already has a reference to Date object ....why not simply set the values of the already existing Date object instead of creating one..?
View 4 Replies
View Related
Oct 27, 2012
How we can write coloured text to a text file in c? Can I use cprintf funtion with any kind editing
View 1 Replies
View Related
Apr 3, 2013
I'm just starting coding and I just want it to input a date, then output a day of the week.
Code:
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int startday = 0, sm = 1, sd = 1, sy = 2000, cm = 0, cd = 0, cy = 0;
cout << "Please enter the current month, day, and year: ";
[Code] ....
View 1 Replies
View Related
Jun 22, 2013
I am learning c because I want to get back into programming microcontrollers, which I previously did in assembly. I wanted to make something fairly tight in terms of program memory and RAM to show me an output in binary form. When you are troubleshooting a file register or serial interface when you can see the actual bit values (on a small LCD for a micro-controller) and compare it to a datasheet.
Code:
#include <stdio.h>
#include <math.h>
int main() {
int i;
int decimaltoconvert;
int convertingarray[7];
int convertingarray2[7];
[Code] .....
Also, how might I go about putting that into a function that I could call?
View 6 Replies
View Related
Sep 9, 2014
I'm trying to write a program that takes input from the user (thats a char) and outputs it to the monitor in hex form.The program is meant to continuously take input from the user then output to the monitor in hex form until an EOF is detected this triggers the program to close.The following code does this except that I get a lower case 'a' at the end of each output.I think the 'a' has to do with the enter key and if that is the case how can i tell the program to ignore this input from the user.
Example: input from user: ABC output to monitor: 41 42 43 a
Code:
#include <stdio.h>
int main(void) {
char myChar;
while(EOF != (myChar = getchar())) {
printf("%x ",myChar);
}
system("pause");
return 0;
}
View 5 Replies
View Related
Sep 3, 2013
When I try to run the code, I get a segmentation fault core dumped, it returns 139 (0x8B)
The file it is pulling from is a list of numbers, but without the string, the output ends up going from values of ~70,000 to values around 50
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#define MAX 29656
using namespace std;
string el[MAX];
ifstream file1("results.txt");
ofstream file2("Energy1.txt");
[Code] ....
View 1 Replies
View Related
Jan 23, 2014
so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values
*/
#include <stdio.h>
int main(void) {
/* Declare an array of integers */
int Grades[5];
int nCount;
/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)
[Code]...
View 3 Replies
View Related
Jun 3, 2013
I need to do program where i will input sentence and then output it in reverse order. Example: today is Monday ----> Monday is today. So I have this:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char niz[20],niz2[20];
int lenght,k=0;
[Code] ....
For output I only get one word of sentence,example: Monday is today--->today and nothing else.
View 5 Replies
View Related
May 6, 2014
The documentation of the class filebuf in the reference of cplusplus.com says:
Objects of this class may internally maintain an intermediate input buffer and/or an intermediate output buffer, where individual characters are read or written by i/o operations. These buffers are synchronized with the contents of the file once filled up, when explicitly requested to do so (sync), or when the object is closed.
Objects of this class may be explicitly made unbuffered by calling member pubsetbuf with both arguments set to zero (see member setbuf): Unbuffered file stream buffers perform the i/o operations directly on the file, without an intermediate buffer.
The C++ standard ensures that filebuf objects have an intermediate input/output buffer/s (i.e, the default constructor of the class filebuf creates the intermediate buffer/s)?
The standard C++ library only allows unbuffering filebuf objects (as the above quote says) but doesn't allow forcing filebuf objects to be buffered.
I have been seeying the concrete implementation code of the standard C++ library in my Windows Operating System (Windows 7 Ultimate 64 bits Service Pack 1) and it seems that fielbuf objects never uses intermediate input/output buffer/s, they use FILE streams of the standard C library instead to do the work. Are this FILE streams always buffered? If true, are they fully-buffered or line-buffered? what is the size of the buffers (perhaps macro BUFSIZ from <cstdio>)? and can I change this size?
I am worried about performance in reading and writing from/to files: if the default behaviour offers the best performance (perhaps if files are too large is better force buffering and choose a larger buffer size).
View 2 Replies
View Related
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
Oct 15, 2014
I'm in a CIS 143 class which is Introduction to Programming using C++. We've been assigned a lab with little to no detail on how to do the things listed.
The purpose of this lab is to practice the file input and output concepts. For this lab you may assume that the input files exist and contain appropriate data inside of them.
Four separate text files* which contain the following lines, different for each file.
(*: This isn't on the lab, but don't worry about what the name, age, id, and major are. those can be random and I can just change them what they need to be)
Name
Age
Student ID Number
Major
Your program should ask the user which of the four input files they would like to open, and then read the contents from the file. Once the contents have been read in, it should output to both the screen and a file named "output.txt" the four values were read in, arranged as follows:
"Hello <name>! You are a <age> years old <major> student, and your ID number is <ID number>"
Now I am by no means saying "Do it for me". I just need to know how to have a user type file1, file2, file3, or file4, and then have the program open that file, then have the output.txt file arrange the wording into the sentence above.
This is what I have so far and I don't think it is anywhere near correct:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFile;
string file1;
string file2;
[code]....
View 1 Replies
View Related