C++ :: Aligning Output Using Setw

Mar 21, 2013

I'm trying to align my output but I can't get it to look perfect. This is how it looks like in my program:

Hitch 98% FRESH
Happy Gilmore 99% FRESH
Transformers 2 100% FRESH
SpongeBob 10% ROTTEN

And this is how I would like it to look:

Hitch 98% FRESH
Happy Gilmore 99% FRESH
Transformers 2 100% FRESH
SpongeBob 10% ROTTEN

Here is my code:

void PrintAll(ostream& out, const string titles[], const int ratings[], int count) {
WriteLine(out, '=', 50);
out << "PRINT ALL" << endl;
WriteLine(out, '-', 50);

[Code] .....

View 5 Replies


ADVERTISEMENT

C :: Aligning Struct To A Page

Nov 22, 2014

I am a bit unsure about what this piece of code aligning a struct to a page is trying to achieve.

Code:
#define PAGESIZE 1 << 12

typedef struct __attribute__((aligned(PAGESIZE))) x86_pagetable {
x86_pageentry_t entry[PAGETABLE_NENTRIES];
} x86_pagetable; It is an piece of code from an educational operating system WeenyOS.

What is the essence of aligning a struct to a page?

View 10 Replies View Related

C++ :: Centering Text With SetW Or SetFill Without Using String Or Function?

Jan 30, 2012

My question is simply how do I center the lines on top of one another using setw (without the use of an additional header file or an additional function)?

I've attempted
Code:
setfill(' ')
to no avail as well.

I can manually set the numbers of setw of course, but I was hoping for alternative smarter fix (without having to pain staking manually set & test each setw).

Note for reason I cannot use an additional header file or function: I've always wanted to know if this could even be done without the use of the <strings> header file (and without the use of an accompanying function). That, and I wanted to reduce the amount of lines of code if possible. If there's not an easier way that's fine (just wanted to know if setw or setfill could get the centering job done alone).

I didn't think it could be done (I believe with the header files I have and place & with no additional functional support one would have to simply manually set each setw).

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
char Enter;

[Code] ....

View 2 Replies View Related

C :: How To Get Output Of Program

Dec 8, 2013

how to get the output of this program.. I'm not completely lost but I need it in the simplest terms.

Code:

/*Recursive Trace
Written by Ron
April 2006
*/

[Code]....

View 9 Replies View Related

C :: Possible To Output By Using Only One Loop

Jul 21, 2013

is it possible to output like this using only one loop? if yes, how?

target output Code: ABCDE

EDCBA here is my code but using one loop im not getting my target output Code: #include <stdio.h>

main()
{
int x, y;

for(x='a', y='e'; x<='e'; x++, y--)
{
printf("%c
%c", x, y);
}
getch();
}

View 6 Replies View Related

C++ :: Output Array To CSV?

Sep 21, 2014

So I have an array portfolio [i][j] where i and j are determined by inputs by the user. I can get the code to fill the array with the correct values; however, I can not figure out how to output the array to csv.

Is there a simple way to output to a csv? Is it easier to create the csv file and just write to it?

This is all I have so far:

for( i=0; i<sizevol; i++){
for(j=0; j<sizespot; j++){
myfile.open ('')
}
}

View 1 Replies View Related

C++ :: How To Use One Function Output In Another

Mar 17, 2013

In my code the cout phrase is supposed to give me an angle in degrees. no matter which 2 points i enter in, it always outputs the angle between them to be 57. This is because the acos value of 0 in degrees is 57. The program compiles without error.

Here is the code:

/*
Synopsis: This program reads in the coordinates of two 2D vectors and outputs the angle between the vectors in degrees.
*/

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// function prototypes
// ENTER FUNCTION PROTOTYPE FOR normalize() HERE.
void normalize(double & x, double & y);

[Code] .....

View 2 Replies View Related

C++ :: How To Output From TXT File

Aug 20, 2014

So I have a .txt file with, Name >> Username >> password >> adminstatus. It is filled with various names. for e.g.

Bob bobby bob123 1
tim timmy tim123 1
rit ritty rit123 0
john johnny john123 0
mary maryy mary123 mary 1

1 will represent admin in the program and 0 will represent a normal user. I want to make part of the program do something like this. > If adminstatus = 1, discount rate =3%. The thing is I will be using UDF to do so and I am unsure of how I am going to read for each user. What I mean by this is. If tim logins, how do I read ONLY tims line's admin status.

Currently I have a Login UDF. for that UDF I return something I named Loginstatus. If the login status = 1 . It will run the current problem that I'm trying to solve which is displaying the user adminstatus's discount rate. So how am I suppose to display the line of the user that logged in.

Here is the simplified explanation of my program. The user will login ( the program will see if everything matches up[username/password] then return loginstatus =1 if the user login successfully) Once the user logs in the program will bring up a menu which will have 2 options.

1. it will let the user check it's current discount rate.
2. quit.

View 2 Replies View Related

C++ :: How To Output A Table

Oct 1, 2014

How would I output a table in C++? I did it a while ago, but I do not remember how, nor do I have the source for the program I did it in.

View 2 Replies View Related

C/C++ :: Output In 3 Columns?

Apr 8, 2015

I have this code down except I'm very confused how to make the output come out in 3 columns.

#include<iostream>
#include<fstream>
using namespace std;
int main() {
int i, j, n, flag = 0, prime_number = 0, temp;
cout << "Enter first prime numbers that will be used or -1 to end:" << endl;
[Code] ......

My output right now is:

Enter first prime numbers that will be used or -1 to end: 20
Twin Prime Number : (3,5)
Twin Prime Number : (5,7)
Twin Prime Number : (11,13)
Twin Prime Number : (17,19)

But what I want is:
1. {3;5} 2.{5,7} 3.{11,13}

4. {17,19}

View 1 Replies View Related

C/C++ :: Output Displaying As 0?

Mar 5, 2015

I am trying to write a c program to convert centimeters to inches and then to feet. I have most of the code written but not sure how to debug it. I keep getting "0" as all of my output.

#include <stdio.h>
// Main Function
int main(void)

[Code]....

View 2 Replies View Related

C/C++ :: Getting Output To Display?

Mar 19, 2015

So I'm trying to generate a very specific list of numbers, but I can't get output to actually display.

#include <stdio.h>
int num[30000];
int num2[30000];
int num3[30000];
int num4[30000];
int diff2[29999];

[code]....

View 3 Replies View Related

C++ :: Output Displaying Out Of The Screen

Feb 11, 2014

I have turbo c++ on windows xp SP2.....whenever i compile my code in turbo c++ i am getting output outside the screen.....but when i used code::block....i get the correct output...fits to screen ...

View 7 Replies View Related

C++ :: Unexpected Output In Example Function

Jan 21, 2015

I am currently trying to understand why this example for using an array as an argument in a function has a different result than what the lecture notes say it should be.

So supposedly sum should return with the value 28, but I get 27 no matter what. I also am not very good at reading and understanding what exactly the order of operations for this function are.

Code:
#include <iostream>
using namespace std;

int sum(const int array[], const int length) {
long sum = 0;
for (int i = 0; i < length; sum += array[++i]);
return sum;

[Code] ....

View 3 Replies View Related

C++ :: Missing A Line From The Output?

Apr 4, 2013

I'm not too sure why I'm missing a line from the output. I've been going over my code like crazy and something seems to cause a line which would be size = 0: [nothing here] missing in my output. Here's my code:

Code: class binSTree: public binTree<T>{
public:
void insert(const T& x); //insert node with value x
bool search(const T& x); //searches leaf with value x

[Code].....

Other files are included but they are 100% correct as I used them in my past couple of assignments. The public version of remove is suppose to call the search function and determine the result of the search for a leaf with value x. Calls private remove and returns true. Otherwise it returns false if the search isn't successful.

View 5 Replies View Related

C++ :: Output Is Showing Address Instead Of Value

Dec 7, 2013

I've run across this issue before, but for the like of me, I can't figure out what keeps causing it. The problem compiles and runs as expected; however in the salaried object (Employee #1 in main.cpp) the console displays the number of vacation days as -858993460 instead of the value entered.

The parent Employee class is abstract with calculatePay() and displayEmployee() being pure virtualls and with a Benefits, Salaried, and Hourly class derived from it.

The Salaried displayEmployee() and the portion of the Main.cpp that contains the salaried object follows. What causing this?

Salaried displayEmployee()
Code:
void Salaried::displayEmployee()
{
cout << endl;
cout << "Employee Information" << endl;
cout << "----------------------------------" << endl;
cout << "Employee Name: " << setw(7) << FirstName << " " << LastName << endl;
cout << "Gender: " << setw(12) << Gender << endl;

[Code] .....

View 2 Replies View Related

C :: How To Avoid Negative Output

Jul 12, 2013

I have a c program that I partially have working. The problem is basically writing a program that allows the user to input the amount of calories they plan to eat a meal and disperse the calories from top to bottom. My program produces the output in the example if I enter 1050 but the issue I noticed if the number of calories is just enough to cover the burgers I get negatives in the other variables.

For example, if I enter a total amount of calories of 1050, I can eat: Output: 2 burgers @ 770 calories (1050 - 770 = 280 calories remain) 1 bag of pretzles @ 170 calories (280 - 170 = 110 calories remain) 1 pear @ 80 calories (110 - 80 = 30 calories remain) 6 tsp. ketchup @ 30 calories If I input 1050 I get the above output but if I input a different integer such as 2000 this is my output 5 burgers @ 1925 calories 0 bag of pretzles @ 0 calories -1 apple @ -80 calories -35 tsp. ketchup @ -175 calories I can't give the full code since this assignment holds a lot of points and was up all night getting it work.

So I'll provide pseudocode

define all 4 variables burger 385, pretzel 170, pear 80, ketchup 5 print out text How many calories can you eat prompt user input
Divide user input into burger How many burgers can bet eaten subtract calories eaten from original user input
Divide calories left into pretzel How many bags can bet eaten subtract burger calories from pretzel calories
Divide calories left after preztel into pear How many pretzels can be eatn subtract pretzels calories from pear calories
Divide calories left over into ketchup how much ketchup can i use show on screen (int total)of burgers @ (int calorie total) calories show on screen (int total)bags of pretzels @ (int calorie total) calories show on screen (int total)pears @ (int calorie total) calories show on screen (int total)teaspoons of ketchup @ (int calorie total) calories

The problem I see is that subtracting the calories from the pear from the left over calories of the pretzel calories leads to a negative. If leftover calories minus 80(pear int) its less then 0 . The calculations from the pear onward to ketchup become incorrect resulting in negative output.

View 6 Replies View Related

C :: Redirecting Output To A File

Jan 16, 2014

i am writing a c program, that sets up serial communication with my modem. The program works so far but i want the output to be redirected in a .txt or .csv file.

Code:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

[Code]....

View 2 Replies View Related

C :: Unexpected Output With Char

Sep 14, 2013

I tried running the code below and i got an unexpected output

Code:

#include<stdio.h>
void main() {
char a='A';
while(a)

[Code] ....

The code is supossed to give an infinite loop but instead it terminates with a=0...I tried running it with some casting like this

Code:

#include<stdio.h>
void main(){
char a='A';
while((int)a)

[Code] ....

But the output was the same as before.why the code has this unexpected behaviour???

View 7 Replies View Related

C :: Redirecting Input And Output

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

C :: Can't Get A Double Type Output

Apr 1, 2014

this is what I got so far

Code:
#include <stdio.h>
#include <stdlib.h>
int main() {

[Code].....

he problem is that when I print out the three sums at the end of the program I dont get any decimal points but just zeros like something.00 instead of something.50 etc

View 3 Replies View Related

C :: Program To Output PPM File

Oct 8, 2014

How do you make a program output a ppm file?

Code:
#include <stdio.h>
void make_pixel
(
int r, // red intensity

[Code].....

View 7 Replies View Related

C :: Using Fwrite With Text Output

Mar 9, 2013

I have the following code:

Code:
void Plot(int nx, int ny, double x[350], double y[350], double C_new[350][350], int iplot){
int i, j;
char fname[50];
FILE *fp;

[Code]....

I am then taking the generated file and importing it into a plotting program (Techplot360). It would speed up the importing process if I created a binary file instead of a like above. I know that I need to use fwrite but I am unsure how to handle lines like

Code:
fprintf(fp, "TITLE= ABCDEFG_%d
", iplot); and

Code: fprintf(fp, "%f %f %f
", x[i], y[j], T_new[i][j]);

View 6 Replies View Related

C# :: Can't Output Ounces On Screen

Jun 25, 2014

why I can't output ounces on the screen in c#...here's the code:

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter7Problem12
{
class Program
}

[code]....

View 6 Replies View Related

C++ :: Unbuffered Output Need Not Working

Aug 5, 2014

#include <iostream>
#include <conio.h>
using namespace std;
int main(){
char c;

[Code] .....

I need my code to echo the character as it is input like:

View 2 Replies View Related

C++ :: Salary Column Output Zero

Feb 21, 2014

void calcWeeklyPay(double empData[][COLS], const int count) {
double wage;
double hour;
int row;
for (row = 0 ; row < count; row++); {
hour = empData[row][0];
wage = empData[row][1];

[Code] ....

I'm really stuck on this problem...Why is it in my salary column all it outputs its 0? How would i fix this ?

View 2 Replies View Related







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