C :: Void Functions With If Else Construct Not Printing Multiple Lines

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


ADVERTISEMENT

C :: IF Construct And Printing Strings

Apr 26, 2014

This code i made divided a user input into characters and non character. The problem im having is that if a mixed sentence is created, such as 32B, it will only print the 'char string' and not the 'non char string'. But when the sentence is just non characters like 32 it will print the 'non-char string'. So essentially if a mixed sentences is created both of the strings won't be created or printed.(This is only a function by the way).

Code:

Count_chars( char Input[]) {
int i;
for(i = 0; Input[i]; i++) {
if((Input[i] <= 122) &&(Input[i] >= 97)){
printf("Char %c ",Input[i]);
Char[i] = Input[i];

[Code]...

View 4 Replies View Related

C++ :: Read In Lines From A File / Store In Variables Then Construct Instances Of Class

Aug 22, 2013

I can't get my code to compile, i need to read in lines from a file and store them in variables. Then i have to construct instances of my class for how many lines there are in the file and take those variables into them.

I'm getting this error :

"a2.cpp:40: error: cannot convert `Employee' to `Employee*' in assignment"

#include<iostream>
#include<string>
#include<fstream>
void displayInfo();
using namespace std;
class Employee{

[Code] .....

View 1 Replies View Related

C :: Printing From Void Pointer

May 26, 2014

Code:
int main() {
List* newList= lst_new();
names* nama;
char* data;
int x=1;

[Code] ....

I cant seem to be able to print a string.. the functions lst_next() lst_first() return void*.

View 9 Replies View Related

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 View Related

C++ :: Non-Void Functions With Argument

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

C/C++ :: How To Use Void Pointer Functions

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

C++ :: Using Void Functions To Display Arrays

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

C++ :: Adding Sums With Void Functions

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

C++ :: Passing Ints To Void Functions

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

C++ ::  Loading File With Multiple Lines

May 17, 2014

I'm trying to load a file that look like this:

IP:123.123.123.123
Port:12345

I can't figure out how to load multiple lines. I tried using , but I can't get it to work. Is there a better way of doing it than I am right now? This is my code.

char message[100];
int messageCount = 0;
for(unsigned int i = 0; i < file.size(); ++i) {
message[i] = file[i];

[Code] ....

View 1 Replies View Related

C++ :: How To Store Multiple Lines In Array

Oct 13, 2013

int statarray[] = {61, 66, 47, 50, 372,
62, 66, 47, 50, 372, 50, 54, 64, 45, 331, 49, 52, 58 69, 356,
58, 80, 50, 48, 389, 76, 64, 60, 59, 401, 76, 59, 57, 54, 422,
53, 45, 45, 52, 253};

I'm getting a bunch of different errors with this, how do we do this?

View 2 Replies View Related

C++ :: Void Functions - Passed By Value To Find A Total

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

C :: Inputting Data From Multiple Lines Using Scanf?

Aug 1, 2013

How would I go about inputting data from multiple lines using scanf?

So far I have tried a loop and somehow checking for '' but can't seem to figure it out..

E.g I want to be able to scanf the ints below line by line and print them( if that makes sense) .

5 15 20 30 5 6
5 6 8 20 34
5 6 7
5 2
2 6 7 2 1 6

This is what i've tried so far, but am really lost!

Code:

int input;
while(scanf("%d", &input)){
printf("%d",input);
if(input == '
'){
continue;}}

View 13 Replies View Related

C++ :: Converting Multiple Lines Of Strings To Double

Aug 26, 2014

I am trying to convert multiple lines of strings to double with std::stod .... I used the code found on the website:

#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
int main() {
std::string two_doubles =" 22145.365 -3564789";
std::string::size_type K;
double first = std::stod (two_doubles, &K);
double second = std::stod (two_doubles.substr(K));
}

The string starts with white spaces. I get this error message when compiling:

warning unused variable 'first'
warning unused variable 'second'

How do you convert the two numbers in the string two_doubles to doubles?

View 2 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# :: Using MessageBoxButtons Dialog With Multiple Lines Of Text And Parameters

Jan 31, 2014

I am trying to make a messageBoxButtons dialog with the 'yes, no' buttons. Im having trouble because of the multiple lines and parameters already in the message, this means that when i declare the messageBoxButtons.YesNo and the title - it throws an error because of the multiple lines etc...

How can I get the yes/no message box to work in this instance?

class Output {
string text; {
DialogResult dialogResult = MessageBox.Show("Please make sure the following information is correct before submitting."
+ " Date: " + Date
+ " Hours worked: " + Hours
+ " Hourly rate: $" + Rate

[Code] ....

View 5 Replies View Related

Visual C++ :: Draw Multiple Lines And Move Them On Screen

Jul 28, 2013

I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines.

I have created rectangle region for each line and trying to move the line.

When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen.

How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC.

View 4 Replies View Related

C++ :: Calculate Angle Value In Form Of Trigonometric Functions - Loops And Void

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

C++ :: Printing Text With Functions

Feb 27, 2014

Any way to make a function that prints something. i wanted to make a function for

Code:

cout << " PAUSE MENU " << endl; cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;

So i wouldn't have to retype it again in the loop, i would just call the function. but it seems whatever i try it doesn't display the text. i've tried making a function with no return time like this " Void Pausemenu(); " but that just goes blank.

Code:

#include <iostream>
using namespace std;
//This function displays different results based on the users input
int menu(int menuchoice);
int main()

[Code] ....

View 4 Replies View Related

C++ :: Program Breaks If Copy Stuff With Multiple Lines Into Console - Clearing Input Buffer

Apr 16, 2014

Using cin.sync() works great so far, but my program still breaks if you copy something with multiple lines into the console.

string test = "";
while(true) {
cin.sync();
getline(cin, test );
cout << endl << "test: " << test << endl;
}

However, if you were to copy this:
1
2
3

and paste it into the program, the output would be1
2
3

test: 1
test: 2

And if you press enter one more time:1
2
3

test: 1
test: 2
test: 3

The 3 finally pops out.

View 2 Replies View Related

C++ :: Printing To Multiple Files Because Output Is Too Large?

Apr 18, 2013

I have managed to make a program that permutates a string with repetition.

I ran it to permutate "abcdefghijklmnopqrstuvwxyz1234567890" with a limit of 5 characters.

This took a little over 5 hours for my pc to process this and I ended up with a .txt 403MB in size. Needless to say I am unable to open this .txt in notepad without Notepad.exe not responding and me having to end the process.

So what I want to do is modify my code to break up the output in to several files rather than one. Possibly all permutations starting with a in one file, b in another, etc.

Here is my current code:
#include <iostream>
#include <string>
#include <sstream>

[Code]....

As you can see it currently appends permutation.txt with all output. I would like it to make files like this permut_5char_a.txt, permut_5char_b.txt, etc.

View 12 Replies View Related

C :: Multiple Functions Within A Program

Jan 22, 2013

I am getting an error on lines 31 and 36 about an expected identifier on my program that computes area and circumference. Is something wrong with my external functions outside of main?

Code:
#include <stdio.h>
#define PI 3.14159

double area;
double circum;

double find_circum (double radius);
double find_area (double radius);

[Code] ....

View 2 Replies View Related

C++ :: Display Last 1000 Lines From Multiple Text Files (log Files)

Jan 16, 2014

I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.

I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.

What is the best way to do this? Even an outline algorithm will work.

View 6 Replies View Related

C++ :: Executing Multiple Functions In Program

Mar 24, 2013

We have been assigned to create a program that uses multiple functions. The professor has given us code for two of the functions, one to open a file and then another one to read the files contents and output them. I have put these into my program but they will not execute. The program does run, but the functions themselves are not executing. I have practiced with other functions that contain no parameters and those run fine, but the functions she gave us have multiple parameters.

The code I have so far is below:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
void PrintFile (string FileName, ifstream& inFile);
int main () {
ifstream inFile;
string fileName;

[Code] .....

View 1 Replies View Related

C/C++ :: Program Using Multiple Functions That Will Calculate Salary?

Feb 21, 2014

I already wrote a program that will calculate the gross pay for a set of employees.

I want modify the code by adding multiple functions.

I want to create a separate function whenever possible to break up the program.

For example, I would like have a function for obtaining the hours from the user, another function for calculating overtime hours, another for calculating gross pay and another function for producing the output.

#include <stdio.h>
#include <stdlib.h>
#define STD_HOURS 40.0
#define OT hour>STD_HOURS
#define SIZE 5
int main() {
int clockNumber[SIZE] = {98401, 526488, 765349, 34645, 127615}; /* employee ID */

[code]....

View 2 Replies View Related







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