C++ :: Functions With Void Returns?
Nov 27, 2014
Write a C++ program consisting of main plus two other functions which will do the following:
Take an integer input from the keyboard.
Send the integer to a function which will output the integer to the screen.
Send the integer to a second function which will tell the user that the integer is an odd value.
Do not tell the user anything if the integer is an even value.
Repeat this process until the user enters something which is not an integer; use input validation to check for validity.
Any not valid input should terminate the program.
View 3 Replies
ADVERTISEMENT
Apr 25, 2013
I having a problem which I'm not able to resovle. I try to dereference a void pointer but I always get a C2440 error. It says: 'static_cast':void* cannot be converted in wqueue<T>. I tried different cast ways but I always get the same error. As far as I found out I should get the error if I try to dereference without cast but in my case I cast before and still get that error.
void *srumbler (void *arg) {
wqueue<workclas*> m_queue= static_cast<wqueue<workclass*>>(arg);
return NULL;
}
The according type wqueue in the header file:
template <typename T> class wqueue {
list<T> m_queue;
pthread_mutex_t m_mutex;
pthread_cond_t m_condv;
[Code] .....
View 3 Replies
View Related
Mar 11, 2014
My assignment is to write a program using VOID FUNCTIONS WITH AN ARGUMENT.
*I need one non-void function with an argument to generate the first 15 numbers greater than 500, another non-void function with an argument to generate the first 15 perfect squares that are greater than 500. Last, they need to be in columns next to each other.* also i cant use x,y, coordinates to align them. i must create a for loop with the
These are some notes from examples in the class. i just don't know how to do it with non void functions with an argument.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
void ClearTheScreen();
void NormalTermination();
[Code] ....
View 5 Replies
View Related
Sep 27, 2014
int (*cInts)(void*,void*);
cInts= &compareInts;
int x=(cInts)(2,5); //This wont work. I tried a bunch of other things
printf(x);
View 5 Replies
View Related
Nov 8, 2013
I want to write a code that gets three values from the user and puts them into three arrays. When the user enters -999, I want to print out a chart showing all the values they put in. This is what I have so far but it wont build. It tells me std::string is requested, but I'm not sure where to put it, and printArrays is declared void. How can I fix this?
#include <iostream>
#include <string>
using namespace std;
const int ARSIZE = 400;
void printArrays (string reportTitle, int levelsArray[], int scoresArray[], int starsArray[], int i);
[Code] ....
View 2 Replies
View Related
May 3, 2013
1) This first function initializes an array of 30 components so that the first 15 components are equal to the square of the index value and the last 15 components are equal to the index value multiplied by 3.
2) The second function processes the array by finding the sum of the first 15 components and the sum of the last 15 components to determine which sum is bigger. The output to the screen should do the following:
a)State “The sum of the first 15 components is:” and then show the sum.
b)State “The sum of the last 15 components is:” and then show the sum.
c)State which of the two resulted in the greater sum or if the two sums were equal.
Function: The program uses two subroutines. One to initialize an array and the other to process the array and print to screen results:
#include <iostream>
#include <iomanip>
// Include any other header files you may need.
const int ARRAY_SIZE = 30;
void initialize ( double list[], int index );
void square ( double list[], int index );
void threeTimes ( double list[], int index );
void output ( const double list[], int index );
[Code] .....
View 4 Replies
View Related
Mar 19, 2014
At first i had my int variables in global scope however i cant do the so im trying to pass my variables from my main to the void functions but cant.....
View 1 Replies
View Related
Dec 4, 2014
I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running !
The output should look similar to this:
how much was your shirt?
20
shirt 20.00
tax =1.20
the total 21.20
Code:
include <iostream>
#include <iomanip>
using namespace std;
void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);
[Code] ....
View 1 Replies
View Related
Apr 12, 2014
This code i made is a cent converter from 5 to 95 cents. The problem i'm receiving is when the 'cents' function is sent back to the 'main' function it only prints one line. It seems to just print the first if construct that complies with the statement. Is there anyway i can have this function print multiple cent values? For example if 60 cents was entered it would only print '50c', and i want it to print '50c' and '10c' instead.
Code:
#include <stdio.h>
int x;
void check(int x)
{
if( x < 5)
printf("Less then 5 cannot be calculated
");
else if(x > 95)
[code]....
View 3 Replies
View Related
Jul 24, 2013
This is an assignment which the purpose is to calculate an angle value in form of trigonometric functions. These are the codes that I've wrote so far.
#include <iostream>
#include <cstdlib>
using namespace std;
void menu(double &value) {
system("cls");
cout<<"*****Trigonometry Program*****"<<endl;
[Code] ....
I have completed the codes for the interface part. Before I proceed with the formula for the trigonometric functions, I would like to make sure the program is Error-free, which if there is accidental invalid input from the user, the program would the user to enter another input until it is a valid response.
The only problem I have encountered for this matter was in menu(value)
If I enter an integer, the program will proceed without error. However, If I enter a character, the program will slip into an endless loop which constantly shows this
*****Trigonometry Program*****
Please enter an angle value => Is the angle in Degree or Radian?
Type D if it is in Degree
Type R if it is in Radian
Your response=> 0 //my initial input for value
Do you want to continue?
Type Y to continue
Type any other key to stop
Your response =>
Where is the source of the problem? I'm pretty sure it's the loop, but I don't know what to do.
View 2 Replies
View Related
Feb 7, 2013
I am trying to get each step down before proceeding to the next one for my problem. I have started my program into returning the Area and Volume of a cylinder. The return numbers I get are huge and I cannot figure out why.My header file
class cylinderType {
public:
void getRadius(double rad);
void getHeight(double heigh);
double area();
double volume();
[code]....
View 17 Replies
View Related
Sep 4, 2013
I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
Code:
//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;
[Code].....
View 11 Replies
View Related
Jun 24, 2013
For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:
bool setzen(int x, int y){
if(feld[x][y]!=3){
return mine=false;
}
[Code]....
Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.
View 6 Replies
View Related
Feb 1, 2015
I am using Excel 2013, Visual Studio 2015. I began learning about Excel XLL. I wrote simple function which tests whether the argument is missing. Here's code:
#define DllExport __declspec(dllexport)
static LPWSTR rgFuncs[1][7] = { { L"GetSum", L"BU", L"GetSum" } };
DllExport double WINAPI GetSum(LPXLOPER12 arg)
{
if (arg->xltype == xltypeMissing) return -1;
return arg->xltype;
}
This code works as expected: if I miss argument, it gives me -1, and the type otherwise. But when I change code to this:
DllExport double WINAPI GetSum(LPXLOPER12 arg)
{
return (arg->xltype == xltypeMissing) ? -1 : arg->xltype;
}
then, when I miss argument, it gives me 4294967295. Why?
View 2 Replies
View Related
Feb 27, 2014
So, I have been working my way through lines of code, and practicing quite a bit. In fact, I have done programs far more complicated than this and still I cannot get it to work.
The idea of the code is to take a number input by the user through the terminal and check if it is a prime number(It does this) If the number is not prime it takes that number and checks for N amount of primes that is put in through the console. When a prime is found it writes that to the console until the N amount of primes have been found.
#include <iostream>
using namespace std;
int prime(unsigned long long x);
int main() {
long long x;
long long y;
long long z;
[Code] ....
At least that's my goal. Currently it will accept the number and check if it is prime. It will then ask for the N amount of primes but will not return any primes. I have check with numbers a I know have prime factors. I have added the comment //XXXXXXXX To show where the problem appears to occur.
View 1 Replies
View Related
Oct 7, 2014
How can I show elements of a vector that is returned by a function in main() ?
Code:
vector<int> merge_sorted(vector<int> a, vector<int> b){
vector<int>temp;
int count = 0;
if(a.size() < b.size()) count = a.size();
else count = b.size();
[Code] .....
View 12 Replies
View Related
Oct 9, 2013
I am using the first method, listed here.
I want to take the time measurement of a construction of a tree, which contains about 2841482 nodes (inner and leaves). Here it is:
Code:
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
Tree t(...);
clock_gettime(CLOCK_MONOTONIC, &end);
int64_t time;
time = timespecDiff(&end, &start);
std::cout<<"Time: " << time << " ns
"; which gives me always a negative value, like -13481628 ns.
View 9 Replies
View Related
Apr 24, 2014
I need writing a macro that would return true/false (1/0) )value. I want to check if a certain element exists in the array. The macro will accept array, its size, and the value to be compared, and must return yes or no. Here is the code that I have written:
Code:
#define EXISTS(T, a, n, val) do {
char ret=0;
T *a_ = (a);
size_t n_ = (n);
for (; n_ > 0; --n_, ++a_){
ret = (*a_ == val);
}
}
while(0)
How can I get the result from this macro.
View 6 Replies
View Related
Dec 24, 2013
to return the array i shall make a pointer function thats ok.. but how do I get the size return if i dont know the size?
if I need to make AXB=C and output C my new array doesnt have a size..
View 7 Replies
View Related
Jul 11, 2014
I have this function that is supposed to take a float as a parameter and then call the getLine() method to accept the users input. The function basically just checks to see if what the user input was of the same data type, if it is it returns the input value, if not then it keeps looping through taking new input until its correct. The problem is no matter what number you put in the output always returns as 140734799803512.
float InputValidation(){
float num;
string strInput;
while (true){
getline(cin, strInput);
[Code] ....
You also need to include <string> and <sstream>.
View 3 Replies
View Related
Mar 8, 2013
Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.
View 3 Replies
View Related
May 15, 2013
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){
... // some local value definition
for(int i = 0; i < 1000; i++){
... // a lot of calculations done here
return i; // -> return the value after each loop is done
}
}
Here it only returns one value, i = 0. Clearly it's wrong.
View 10 Replies
View Related
Nov 25, 2013
I need to make a program that returns pascal's triangle of N rows. I actually need to make a function of format "int **func(int n)". I don't know how to go about that, so I am trying this method first, but I seem to be getting an endless loop.
Code:
#include <stdlib.h>#include <stdio.h>
int *rowN(int rowNum, int* prevRow) {
int *rowN;
rowN=realloc(rowN,(rowNum+1)*sizeof(int));
[Code] ....
View 7 Replies
View Related
Oct 24, 2013
I'm writing a function that is to return the price of something.. What would be the most appropriate return type for this? Like in Java it would be a double...
View 6 Replies
View Related
Mar 1, 2013
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
View 8 Replies
View Related
May 5, 2014
How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".
To do this would I just use an array?
View 4 Replies
View Related