C++ :: Logical Error - Change Value Inside Void Statement

Jul 16, 2013

I've encountered a slight logical error in my code

/*
Lab06_pensionplans.cpp
Purpose :
- Create a simple financial application to calculate retirement plans
*/
#include <iostream>
#include <cstdlib>
using namespace std;
void displayMenu() {
system("cls");

[Code] ....

Look at case 2, which the user supposed to key in a new input, the problem is the value will never got into main function, I don't know what should I modify with the function.

Figured out I need to change the

void changeData(int startingAge, int numOfYears,
double lumpSumAmount, double yearlyAmount, double interestRate )

into

void changeData(int &startingAge, int &numOfYears,
double &lumpSumAmount, double &yearlyAmount, double &interestRate )

View 2 Replies


ADVERTISEMENT

C++ :: Next Permutation Logical Error

May 11, 2013

I wrote this code to solve a problem in which the user inputs a permutation of size 'N' and the next permutation of the same elements has to be generated.

I went about this in this way: given 3 2 5 4 1, starting from the right, the first no. has to be searched which has a no. greater to it on its right. Here it is 2. Now an array is generated containing all no.s on its right and greater than it. For 2, it is: 5,4. Out of these the smallest member is searched for and switched with 2. So, 4 is switched with 2 to get the Next Permutation: 3 4 5 2 1.

The code I wrote does not show any error but does not return the correct value when run and gives the same value instead. If I enter '3 2 5 4 1' it returns the same value as the answer.

#include<iostream.h>
#include<conio.h>
void main() {
clrscr();
int N,M,i,n,c,swap,flag,count,small,m;
int Array[100],Key[100];

[Code] .....

View 2 Replies View Related

C++ :: Online Shop - Serious Logical Error

Nov 15, 2013

My project is on an online shop in which you can manage a shop(adding ,deleting ,clearing and modifying items) also you can switch to different shops(all shops are same)

Code:
#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

[Code] ....

The logical problem is serious because i am not able to find the error!!! There is some problem with display lines in void shop()-->if(mode=='s') and if(mode=='d'). I add only one item but in output screen i see two items(sometimes >2)
*note* to run the above display lines in the output screen....first register--->add atleast one item--->see your shop

View 12 Replies View Related

C++ :: Logical Error In Output Of DAYNAME

Oct 31, 2014

I have to write a program that does the following: Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 - 7 array , where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". The program should first prompt the user to input the data for each monkey, starting with "Sunday" for monkey #1, then monkeys #2 and #3, followed by "Monday" for monkey #1, then monkeys #2 and #3 and so on, through "Saturday". The program then creates a report that includes the following information, each properly labeled (see below):

-Average amount of food eaten per day by the whole family of monkeys.
-The least amount of food eaten during the week by any one monkey.
-The greatest amount of food eaten during the week by any one monkey.

Input Validation: Do not accept negative numbers for pounds of food eaten. When a negative value is entered, the program outputs "invalid (negative) food quantity -- re-enter" and attempts to reread the value . Prompts And Output Labels: Decimal values should be displayed using default precision, i.e. do not specify precision. Each item read should be prompted for by a string of the form "Enter the food eaten by monkey #N on DAY:" when N is 1 or 2 or 3 and DAY is "Sunday" or "Monday" or ... or "Saturday".

The output should be of the form:

Average food consumed daily: 6.23
The least daily food consumed was by Monkey #0 on Friday
The most daily food consumed was by Monkey #2 on Sunday where the specific amount of food or specific monkeys or specific days identified depend on the actual input.

However after the process of resolving the errors unable to convert to standard string and unresolved externals I now have a logical error that causes the output of the DAYNAME variable to output as what appears to be hex in the following picture:

How I can fix this and why it's casting them as this in the output.

My full code is as follows because I don't know exactly, which line of code is causing this to happen:

Code:
//
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// constants
const int MONKEYS = 3;
const int DAYS = 7;

[Code] .....

View 5 Replies View Related

C :: Void And Return Statement

Jan 11, 2014

If i declare a function as a void function. But for testing purpose if i use a return statement in the function definition. i have tested and found that the function does not return and executes the entire function. How does the function not return even if a return statement is available? Does the compiler removes this return statement or how it is?

View 2 Replies View Related

C++ :: Add Variable Address To Void Pointer Inside Of Class?

Dec 1, 2013

How can I add the variable adress to a void pointer inside of a class?

class variant2 {
private:
void *Vvariant=NULL;
public:
template<typename b>
variant & operator = (b *adress)

[Code] ....

if possible i want avoid the '&' when i assign the variable address.(variant2 f=varname;//like you see i don't use the '&')
for the moment i just need put the address to Variant pointer. but i receive several errors .

View 4 Replies View Related

C++ :: Defining Classes And Using Them Inside Void Main Function

May 18, 2013

This is a program I developed in which we had to define a class named BOOK with the data members and member functions as shown in the program..We have to:

(i) Make the user enter the values in the array BOOK.
(ii) Display the details that the user entered.
(iii) Search for a book from the array upon its Bno and display its details.
(iv) Search for a book from the array upon its Bname and display its details.

PROGRAM:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class BOOK {
private:
int Bno;
char Bname[20];

[Code] .....

But while running it the compiler gives the errors as:

Line 43 to 48: Illegal character '' (0x5c)
Line 69: Undefined symbol 'Display'
Line 88: 'BOOK::Bno' is not accessible.
Line 89:'BOOK::Bname' is not accessible.
Line 90:'BOOK::Author' is not accesible.
Line 91:'BOOK::Price' is not accesible.
Line 108:'BOOK::Bno' is not accessible.
Line 109:'BOOK::Bname' is not accessible.
Line 110:'BOOK::Author' is not accesible.
Line 111:'BOOK::Price' is not accesible.
from 43 to 48..the line feed was also used at many other places but there it was not given as an error so why here?
Line 69: I defined the Display() function outside the class since it contained control structures, so what's the error then?

About the lines the rest of the error( the "not accessible" ones) I know these data members are not accessible because they are in private visibility mode. But then how to make them accessible? (Without putting them in public because it was a part of the question to create the data members in private).

View 1 Replies View Related

C++ :: If Statement - Void Function Not Calling

Nov 2, 2013

I've been trying to get my program to call void functions with an if statement, but when i run my program and try to call one of the functions "worst case, best case, or random case" it doesn't get called. It just prompts the original menu.

#include<iostream>
#include<fstream>
using namespace std;
void bubbleSort();
void selectionSort();

[Code] .....

View 1 Replies View Related

C :: Sorted List - Why Value Of Void Pointer Change

Feb 16, 2014

I have a the following in a header file.

Code:

struct SortedList{
void * data;
struct SortedList * next;
struct SortedList * previous;
int (*compareFunc)(void *, void *);
void (*destructor)(void *);

[Code] ....

In a .c file, I implemented the SLCreate function.

Code:
SortedListPtr SLCreate(CompareFuncT cf, DestructFuncT df){
struct SortedList item;
item.data = NULL;
item.next = (struct SortedList *) malloc(sizeof(struct SortedList));

[Code] ....

In main.c, I try to do the following:

Code:
SortedListPtr list = SLCreate(&compareInts, &destroy);

A bunch other code that does not alter list or it's contents at all.

struct SortedList item = (*list);
void * data = item.data;
if (data != NULL) {
printf(Why did data become not null???
"); }

How come my variable data became not null anymore when I haven't altered it at all....

View 2 Replies View Related

C++ :: Having A Function Inside For Each Statement

Dec 4, 2014

I keep on getting error message while trying to pass a function inside a for_each loop.. I have a vector and i used for_each loop to go through the rows in that vector, Now I need a function to do something

Example this is what I am trying to achieve

for_each (label.begin(), label.end(), addToTemporaryVector());
void DataPartitioning::addToTemporaryVector(){
cout<<"sucess";
}

But I get an error message saying: error: invalid use of void expression

View 2 Replies View Related

Visual C++ :: Access Violation Reading Void Assigned Dynamically Allocated Value Inside Function

Sep 16, 2013

Why the void pointer passed to testb doesn't continue pointing to the allocated integer after the function call returns.

Code:
#include <stdio.h>
#include <iostream>
void* testa() {
return new int(1);

[Code] ....

View 5 Replies View Related

C# :: Change Some Input Value Inside Code

May 12, 2014

I need to convert some input values in c#

for example if input is 0.0 then it should take value as 63.

0.5 as 62
1.0 as 61
1.5 as 60
2.0 as 59
2.5 as 58
3.0 as 57
:
:
:
:
28.5 as 3
29.0 as 2
29.5 as 1
30.0 as 0

now maybe I can define it in enum and use it but before doing that i wanna try if i can put an equation instead of defining these values into memory.

View 2 Replies View Related

C/C++ :: Case Statement After Value Change?

Jan 5, 2015

I am building a tamagotchi like application/game. As for the leveling up and changing of character I am using a char value so that the icon can change as the character progresses.

Due to the fact that the value for level is changing I need it to also change for what is being used for the case statements

I know I cant use variables in case statements because I have tried every way I can think of.

The code is

switch(Area[y][x])
{
case '*':
Area[y][x] = Level;
break;
case 1:
{
CODE
}
}

Where I have the case 1 I need it to change as level increases (as level is starting at 1)

View 5 Replies View Related

C++ :: Error - Void Value Not Ignored As It Ought To Be

May 4, 2014

Using a template in the assignment, I don't know what I did wrong?

Code:
#include <iostream>
#include <string>
using namespace std;
template<class T>
void mpgcalc(T& Miles, T& Gallons)

[Code] .....

View 2 Replies View Related

C :: Error - Invalid Use Of Void Expression

Mar 14, 2014

I keep getting an error "Invalid use of void expression" on line 12.

Code:
#include<stdio.h>
#include<stdlib.h>
void initialiaze_array( int size );
void print_array( int size );
void replace( int num, int i );

[Code] ....

View 3 Replies View Related

C++ :: Error - Variable Or Field Declared Void

Sep 17, 2014

Why I am getting this error

error: variable or field createBinaryFile declared void

void createBinaryFile(std::fstream&, std::ifstream&);

View 2 Replies View Related

C/C++ :: Error Invalid Operands Of Types Void And Int

Oct 22, 2014

I making a simple single number scrambler/encryptor and as I tried to build the console application the following error
occurred:

error: invalid operands of types 'void' and 'int' to binary 'operator%'

The source code is bellow.

#include <iostream>
#include <math.h>
#include <cstdlib>  
using namespace std;  
int main() {
    int nTimer;
    int nInput;

[Code]......

I am running code::blocks as my IDE on Ubuntu.

View 2 Replies View Related

C++ :: Cannot Cast From Void Pointer - Returns Always Error C2440

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

C/C++ :: Error Variable Or Field View Declared Void

Oct 10, 2014

On running the following codes I'm getting these errors. I'm using Code Blocks 13.12

void view(string); //error: variable or field 'view' declared void & error: 'string' was not declared in this scope
void customer()
{
char ch;

[Code]....

View 4 Replies View Related

C++ ::  Why Every First Function Of Each File Get Error - Multiple Definition Of Void Pointer

May 6, 2014

I declared all functions in header file, such as:

bool readCase();

bool meshing();
bool readMesh();

bool calculateFlowfield();
bool readFlowfield();

bool calculateEvaporation();

And then I define them in separated .cpp files, each .cpp file include the header, but I got multiple definition error, why?

Even the int main() function, which only decalred and defined once got this error, why?

View 14 Replies View Related

C++ :: Getting Error Using Enum In If Statement?

Jan 19, 2014

I'm trying to make a simple C++ program in which the user must try to guess a number, if they guess too high it says "too high" and if they guess too low it says "too low".

I also decided to add a feature which allows them to select how many tries they would like to guess the number. I tried to make "tries" type an enum so if the user could not pick an invalid number but for some reason i cannot use it in an if statement.

here is the code and i am getting the first error on line 27:

Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int guess;

[Code]....

View 7 Replies View Related

C :: Error When Compiling WHILE Statement

Mar 6, 2013

Code:
/* Demonstrates using the gets() return value. */
#include <stdio.h>
/* Declare a character array to hold input, and a pointer. */
char input[257], *ptr;

[Code]....

I just got this from the book that I am using and it is for testing for input of a blank line and readers are being warned in using this format (line 18):

Code: while ( (*ptr = gets(input)) != NULL)

What is the correct syntax if a gcc compiler is to be used?

View 8 Replies View Related

C++ :: Syntax Error If Statement

Feb 19, 2012

I got syntax error in if statement ,, i checked the line i put { after the condition don't know where the mistake are

1>c:usershani est11 est11code.cpp(20) : error C2143: syntax error : missing ';' before 'if'

PHP Code:

# include <iostream>
using namespace std;
int seqsearch (int list[],int length,int key);
void main () {
    int marks [30];

[Code] ....

View 2 Replies View Related

C++ :: Switch Statement - Error At Output

Jul 26, 2012

I have a question related to switch statement, which the switch in class employee2 gives me error at output. Program compiled well. I am using Code::Block Compiler V10.5. I have created object of class employee2 in main() function to get data from user, store it and display it. At the output, Compiler doesn't show actual output what i am expecting. The fun thing is my compiler printed emocion like (), where (hourly/monthly/weekly) was supposed to print.

Code:
#include <iostream>
using namespace std;
enum period {hourly,weekly,monthly};
class employee2 {
private :
char ch;
period x;
double compensation;

[Code] ....

View 10 Replies View Related

C++ :: Linker Error / Inlining Methods Inside Header File

Aug 11, 2012

We have a midi.cpp which includes midi_synth.h.

this h file declares a class and this class inlines a open method.

Now the linker doesn't recognize this open method when called by another method inside midi.cpp.

What would I do?

View 1 Replies View Related

C++ :: Employee Database - Bizarre Error With If Statement

Dec 21, 2014

I have written a program that stores employees in a database object. You can Add, hire, fire, promote, demote, and display employees. The program uses an interface, a database class, and an employee class with member functions.

The strange behavior is in my switch statement in interface.cpp. I have a '#' that represents a command line. Add and Display functions are ok, but if I hire, fire, promote or demote. It will display '##' for the next input. I ran the debugger and after hire/fire/promote/demote is called, the first if-statement goes to 'else' and I'm trying to figure out why.

Note: main() calls mainMenu() to run the program

// interface.cpp
#include <iostream>
#include "database.h"
#include "display.h"
void mainMenu() {
displayMenu();
Database* employeeDatabase = new Database();

[Code] .....

Here are the two classes...

// database.cpp
#include <iostream>
#include <vector>
#include <memory>
#include "employee.h"
#include "database.h"
using namespace std;

[Code] .....

View 6 Replies View Related







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