C++ :: Need Cout To Print Function Output?

Nov 16, 2013

Finally got to functions. Made a simple one that adds two numbers:

Code: int add(int a, int b){
cout<<"a+b=";
return a+b;
}

It refuses to give an output unless I use cout.

If I just call the function like so: "add(12, 24);", shouldn't it print out a+b=36? It only prints out "a+b=", unless I use "cout<<" ahead of the call.

My simple question is why does it need cout ahead of the call? Shouldn't "return" do its job and print out the number?

View 2 Replies


ADVERTISEMENT

C/C++ :: Creating Overloaded Cout That Will Print Contents Of Array

Sep 22, 2014

I need to create an overloaded cout that will print the contents of an array. So I can say output << a << endl;

And it will print the contents of the object a... which happens to be an array.

class info:
 
class List {
    public:  
        List();  
        bool empty(); //returns true of false if empty  
        void front(); //makes current position at beginning of list  
        void end(); //makes current position at the end of list  

[Code] ....

I understand this code, I am simply calling the size method from the program, but i don't know how to pass in the array so that i can print it line by line... simple syntax i am sure... but the whole thing is baffling me... I need to be able to call this on any variation of the class, so it cannot be specific to any one array.

View 4 Replies View Related

C++ :: Program That Reads A Word From User And Then Print (cout) This Word

Oct 24, 2013

I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:

Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().

View 7 Replies View Related

C/C++ :: How To Print Output To Array

Nov 10, 2014

At the bottom I have a loop that cout FI,XC,XL,I while going through the loop but when it prints its uneven and setw cant fix it. How do I print values of FI,XC,XL & I to an array so they are aligned.

#include <iostream>
#include <string>
#include <cmath>
#include "projectfunctions.h"
#include <iomanip>
using namespace std;
const double PI=acos(-1);

[Code] ....

View 4 Replies View Related

C++ :: Print Last Digit Of Number Output Always Become 6?

Oct 26, 2013

i just started learning programming and i just wanna know how come when i try to print the last digit of a number the output always become 6?

View 4 Replies View Related

C :: Output Does Not Print On Text File

Jul 19, 2013

In this program I can not print the typed value in the file. The file creation well done but it is an empty file

I press Ctrl +z for EOF

Code:
#include<stdio.h>
int main(void){
FILE *fp;
char ch;
fp=fopen(" Test.txt","w");
printf(" Enter the TEXT

[Code] .....

View 1 Replies View Related

C :: Won't Print Numbers Sorted When Use Print Function

Nov 17, 2013

I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort

Code:

void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}

[code]....

put it wont print the numbers sorted when I use my print function, just the unsorted numbers.

View 1 Replies View Related

C++ :: Make Output Print Out To Screen In Reverse?

May 26, 2013

How can I make the output print out to the screen in reverse?

Code: #include <iostream>
#include <iomanip>
using namespace std;
int getnum();
void Fibonacci(int n);

[Code].....

View 7 Replies View Related

C :: Take Averages Of Whole Week And Output Print Statement

Jul 17, 2013

I wanted to take the averages of the whole week and output a print statement. I've tired few ways this like assigning "temp" a pointer, or in each if statement assigning temp to a new variable like a, b , c etc. Then adding them all up at the end and dividing by 7. My issue is I am unclear how to store the number typed for each if statement while the program is running, then have it compute the simple equation. The code in question is below:

Code:
#include <stdio.h>
int main(int argc, const char * argv[]) {

int i, j = 0, temp = 0;
for (i=1; i<=7; i++) {
j++;

[Code] ....

View 1 Replies View Related

C/C++ :: Print Output With Append Data In TXT File

Oct 22, 2014

I was recently introduced to the fstream header file. I want to know is their a easy way to print an output with append data in a .txt file.

And secondly I am also having an error with my header file. It says error: cannot open source file "fstring" when I hover my mouse over "#Include<fstring>".

View 7 Replies View Related

C/C++ :: How To Print Colored Output In Borland Version 4.5

Feb 26, 2014

I am using borland turbo c++ version 4.5 and for printing a coloured output i used textcolor() but it is showing error that call the undefined function 'textcolor' in main, so what can i do now to print a coloured output???

View 1 Replies View Related

C :: How To Print Out Output String For A Program In Reverse / Backwards

Feb 20, 2013

How to make it so an output for a program would print out the string in reverse/backwards? I was just curious on how to do this.

View 6 Replies View Related

C++ :: Discrepancy Between Constructor Output And Following Print Call To Object?

Jul 5, 2013

I am creating a Matrix class, and one of the constructors parses a string into a matrix. However, printing the result of the constructor (this->Print()) prints what I expect, and an <object_just_created>.Print() call returns bogus data. How is this even possible?

Snippets below:

Matrix::Matrix(const string &str) {
// Parse a new matrix from the given string
Matrix r = Matrix::Parse(str);
nRows= r.nRows;
nCols= r.nCols;

[Code] ....

in the driver program, here are the two successive calls

Matrix mm6("[1 2 3.8 4 5; 6 7 8 9 10; 20.4 68.2 1341.2 -15135 -80.9999]");
mm6.Print();
// mm6.Print() calls bogus data, -2.65698e+303 at each location. The matrix's
// underlying array is valid, because printing the addresses yields a block
// of memory 8 bits apart for each location

View 4 Replies View Related

C/C++ :: Final Output Needs To Print Initial And Final Values

Jan 28, 2015

I have a program that is reading six characters from a text file, swapping every other character(ABCD would read BADC), and then adjusting their value based on a user's adjusted value input. If the adjusted value is 5 then letter A becomes F.

The final output line should print the initial six characters followed by the final six characters after the swap and encrypt adjustment.

I can only manage to print the final characters. Am I far off thinking I need to use pointers to point to the original character values?

One more thing: instructor wants us to complete this project as simply as possible meaning without the use of arrays, loops, switch statements, etc.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main() {
//declarations
char c1,

[Code] ....

View 4 Replies View Related

C/C++ :: Read From File And Print Output To File?

Apr 20, 2014

I know this is how you read from a file. I also want to print my output to the same name of the file plus ".txt". So if my file is called "text" I want to print it to a file called "text.txt".

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

[Code]....

Would it be something like this? Is it better to use "a" or "w" in the fopen? I want to write to it several times.

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

[Code].....

View 2 Replies View Related

C/C++ :: Trying To Cout Vector

Jun 10, 2014

This is what my code looks like

class Transaction{
private:
char type;
double amount;
double balance;
string description;

[Code] .....

This part is what I am having trouble with as this section is not printing anything.

for (int i = 0; i < transactions.size(); i++){
cout << transactions[i].gettype() << " ";
cout << transactions[i].getamount() << " ";
cout << transactions[i].getbalance() << " ";
cout << transactions[i].getdescription() << " ";
}
}

View 2 Replies View Related

C++ :: Difference Between Cout And Cerr

Oct 30, 2013

Other than the theoretical difference between cout and cerr where the former puts values to the monitor and the latter puts values related to errors to the monitor, is there any real difference here? Why not use cout when you want to send anything to monitor? Why use cerr at all?

View 7 Replies View Related

C++ :: Double Values On Cout

Mar 6, 2014

Here is code first:

//fp_screen.h
class fp_screen{
public:
double fps;
double xx3;

[Code] .....

fps:1.16922e+006 // this will happen 80%
fps:900 // this is how it should be

if i do cout << "fps:" << (int)screen.fps << endl;

Somethings number is right like 800 or else
put sometimes its 5423423... something.

What is going on here?

View 5 Replies View Related

C++ :: Cout Not Displayed After While Loop

Sep 7, 2014

Am having a problem with the following program not displaying the cout after the while loop, it doesn't ask if I want to enter another employee but just prompts for the employee payrate again.

#include <iostream>
using namespace std;
int main()
// Parameters: None
// Returns: Zero
// Calls: None

[Code] ....

View 1 Replies View Related

C/C++ :: How To Cout The String Characters Themselves

May 11, 2014

Iam working with arrays and i cant get to the write solution to cout the characters.

the Question is : Write a program that inputs a character string from the user as an input (using cin.get())and store it in myStr[ ] array.Assume that the length of the input string is less than 100 characters and the string may contain lower case, upper case, and/or symbols.The program should then print the number of lower case, upper case, digits, and symbols along with the characters themselves.

my code :

#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
int main() {
int ctr1=0, ctr2=0, i=0, ctr3=0;

[Code] ...

What i have now, how can i cout the uppercase characters and the lower case characters and the symbol characters !

View 3 Replies View Related

C :: How To Print Struct From Another Function

Oct 31, 2013

how to print struct from another function? let's say I have code this way

Code:

struct student{
int id // simple example
};
main(){
modify_data(); // calls the function.
}

[code]....

View 9 Replies View Related

C++ :: How To Print Structure With Function

Sep 19, 2013

I'm trying to pass my structure to a function using switch method, so that It will ask for user's name and age then then from the switch method it will call a print function, but my coding is not working.

View 7 Replies View Related

C++ :: Cout And Cin Objects Of Iostream Class

Feb 17, 2013

i ran the following code in the latest version of code::blocks and it tells me that the objects cout and cin are not declared in this scope. what is the problem?

I used to use Turbo C++ 3.0 and i had no problem whatsoever with that compiler. But now i am trying to move to code::blocks but it is proving very very hard as all the standards have been changed.

I am a school student and thus, we had been told to practice on Turbo C++ 3.0 and now i am unable to unlearn it. Also, if i use printf in place of cout there is no error but i want to use cout as it is what i am comfortable working with.

#include<fstream>
#include<conio.h>
int main() {
using namespace std;
char name[20];

[Code] ....

Is there some document to which i can refer so as to get the latest C++ standards which is C++0x i believe?

View 7 Replies View Related

C++ :: Cout Double Or Float Without Additional 0?

Jun 30, 2013

I m working calculating stuff in files, input and output data, etc..., the question is the following: I output double numbers with:

myFIle << fixed << setprecision(10) << double;

The problem i got is that when a numer is like 193123.2 it prints like 193123.200000..., so finally, ¿how can i print it with any additional 0 that i need?.

View 1 Replies View Related

C++ :: New Project Doesn't Cout Any Values?

Apr 11, 2014

I'm trying to build a new project and i installed some new libraries in it but when i try to compile any code it doesn't give me any value just press any key to continue, i didn't make any files but one and even if i tried to do this simple task it doesn't cout any result:

#include<iostream>
using namespace std;
int main() {
cout <<("ha");
system("pause");
return 0;
}

View 4 Replies View Related

C++ :: Cout Total Element In Array

Feb 28, 2013

I am beginner in C++ programming. I having a problem to show the output of all the element i store at a array called total_price. the output become unreadable.

#include <iostream>
using namespace std;
int main () {
float price[1]={0};
int qty;

[Code] ....

View 6 Replies View Related







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