C :: Using Prototype Functions To Run Loops And To Pause The Program?

Oct 25, 2013

So i have to use these prototype functions to run loops and to pause the program, the only problem is after i select a loop option and enter a number of dots to print in the loop it goes into an infinite loop and why, also when i try using the 4 option to exit it still asks me how many dots i want to print.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int pause(char *);
int getInt(char *);
void whileFunction(int);
void doWhileFunction(int);
void forFunction(int);

[Code] .....

View 12 Replies


ADVERTISEMENT

C++ :: Prototype Functions - Signed / Unsigned Incompatibility Error

Feb 17, 2013

I'm really brand new to C++ and I'm currently learning it for fun. I'm working on prototype functions, and I got an error.

I get an error saying “warning : '<' : signed/unsigned incompatibility” but I haven't defined an unsigned int anywhere. Actually, I don't even really know much about them except that they allow bytes from -127 to 127 instead of 0 to 256 for signed int's if I understood correctly...

The function itself is supposed to make a pointer go to the end of a string and add the Null Byte at the end. There's probably an already-existing way to do so, but I don't know it. Plus it is fun making this.

In the below code I'll be making comments for most lines so you may correct me if I'm not doing what I think I am. Any way, here's the code of my "my_fct.h" header file :

#include <stdio.h> //Includes basic functions necessary in C as 'scanf' or 'printf'.
#include <string.h> //Includes string functions such as 'strcpy' or 'strcmp'.
#include <iostream> //Not sure about what this does.
int strend(char[]); /* Specifies the existence of a function 'strend' that uses a char
* string as argument and that returns a value of integer type. */

[Code] ....

View 3 Replies View Related

C++ :: How To Pause Program Until File Changes Are Made

Oct 2, 2013

I want to monitor a text file. So far what I have is the program reads and prints the names in the file to standard out. When the program reaches the end of the file, it closes.

I want the program to stay active and continue to print names as they are saved to the text file.

I was toying with FindFirstChangeNotification function, but it seems that returns a handle so I'm back to the drawing board.

View 1 Replies View Related

C :: System Call To Pause Execution Of Program For Few Seconds

Feb 2, 2014

I know there has to be a system call to pause (not system("pause") execution of a program for a few seconds. I would like to give the illusion that my program is 'thinking' rather than just spit out the result as soon as the user has hit the enter key.

View 5 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++ :: 2 For Loops In A Single Program?

Sep 15, 2013

I have to make my program display days 1-30 along side numbers increasing by 5 each day beginning with 6 on the first day. I wrote 2 for loops on separate tabs but now I want to know if its possible to combine them into 1.

For loop 1
int day,;
for (day = 1; day <=30; day = day + 1)

For loop 2
int candy;
for (int candy = 6; candy <=151; candy = candy +5)

View 10 Replies View Related

C/C++ :: Program Is Not Responding Using While Loops

Feb 20, 2014

What I am trying do is this in steps,

1)I took an integer
2)I try to convert it into binary by storing the remainder by dividing it in 2, in an integer array size of 8(array1)
3)But the digits are in the reverse order, so I reverse them(array 2)
4)When the number is less like 40 or 20 there are no 8 digits/bits
5)So further manipulation of bits i need to pad some other value(say its 2)in the beginning of the array where you
will have continuous zero bits.

for(k=0;k<8;k++) {
remZ=devZ%2;
devZ=(devZ-remZ)/2;
z_bit_array[k]=remZ;

[Code] .....

I want to pad another bit apart from 1 and 0 until you find one. for example say the content of array2 will be 00010111 then i need it to be 22210111.But my method is not working and make the program non responsive.

View 5 Replies View Related

C++ :: Creating Menu Program Using Only If And While For En Do Loops

Mar 13, 2014

I just started learning the basics of programming. While encountering one of the practice problems in the book by Alex Allain I got a little confused. The question is as follows:

Write a menu program that lets the user select from a list of options, and if the input is not one of the options, reprint the list.

The author assumes you can answer this question only using if statements and/or loops (while, for and do).

This is the code I've written thus far:

Code: #include <iostream>
using namespace std;
int main()
{
int option;
char reset;

[Code] ....

For some reason, the nested while loop keeps repeating even when you input a valid option (1, 2 or 3). I can't seem to figure out why this happens.

View 4 Replies View Related

C++ :: Program That Loops X Number Of Times

Feb 20, 2015

I'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.

View 2 Replies View Related

C++ :: How To Pause After Outputting Results

Feb 19, 2013

I mean on the executable file. It just displays the results and quickly flashes away, cin.get() has no effect and system("PAUSE") is undeclared.

I never found a single sure way to pause effectively. Is there a method that works all the time? Sometimes cin.get() gets skipped even in the code itself. The IDE I am using is Code Blocks if that matters any.

View 4 Replies View Related

C++ :: Using Enumerations Types In Loops And Conditions - Ignored In Program

Jan 22, 2014

I am trying to use enumeration types in my conditions to make a simple program that calculates area of a square or circle depending on users choice then updates the total area and outputs the total area.

The program builds fine. But it ignores all of my loop conditions and i'm not sure why.

Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;

[Code] ....

View 4 Replies View Related

C :: System Call For A Pause Function

Jan 20, 2014

I know there has to be a system call for a pause function. I simply want the program to pause for a few seconds before executing the next line of code. I do NOT want the user to enter a keypress, just pause the output or code execution for a few seconds.

system (pause); waits for keypress right? I just want it to wait 3 seconds before proceeding. I know it should take an argument for milliseconds right? Also, this is for a homework assignment I have already completed, just doll'in it up a bit for extra credit...maybe...

View 7 Replies View Related

C++ :: Add Small Function To Allow To Pause Game?

Dec 4, 2013

I am trying to add a small function to allow me to pause the game I am making. I measure the time elapsed using the following algorithm:

1. USE ""clock_t begin=clock();"" FOR SYSTEM TIME OF GAME BEGINNING.
2. USE ""cout<<(clock()-begin)/CLOCKS_PER_SEC;"" TO DISPLAY TIME ELAPSED IN SECONDS.

Now, if I want to pause, I would want to subtract the 'paused' time from the total time elapsed.Say,

clock_t pause, resume;
{
pause=clock();
.
.
.
resume=clock();
}

Then I would do cout<<(clock()-begin-(resume-pause))/CLOCKS_PER_SEC;

This, though is what I want, works only once(I can pause only once). I can use arrays of resume and pause, but it would still limit the number of times I can pause.

What I am looking for is a way to pause any number of times.

View 3 Replies View Related

C :: Program That Prints Multiplication Table Using Nested Loops

Mar 9, 2013

Write a program that prints a multiplication table using nested loops. In main ask the user for the smallest column number , the largest column number and the size of the increment. Ask the user for the same information for the row values.

In the example the column values entered are: 5, 15 and 2 and the row values 3, 6 and 1.

Given those numbers you would generate the following table.

Multiplication Table
| 5 7 9 11 13 15 ___|___________________________________ | 3 |
15 21 27 33 39 45 4 | 20 28 36 44 52 60 5 | 25 35 45 55 65 75 6 | 30 42 54 66 78 90
Print the 24 values with the grey background. The other numbers show the values to be multiplied.

Code:
#include<stdio.h>
main() {
int a,b,c,d,e,f;
int i,j,total;
printf("Please enter smallest column number: ");
scanf("%i",&a);
printf("

[Code] ....

Challenge:
As an added challenge try to print out the column
headings (5 7 9 11 13 15) and the row headings (3 4 5 6)

View 1 Replies View Related

C++ :: System (PAUSE) Without Message Or Button Press

Nov 7, 2013

I would like to have my program pause at a certain screen but not to have the "Press any key to continue..." message or the press of a button. In my program, the code looks similar to this:

for(;;)
{
cout
cin
cout
cin
...
//

here, I want to have a pause to view what the for loop has come up with but to not have a message display or a button press needed. At the end of the loop, I want it to pause before looping again. IS this possible?

If so, how can I implement it into my program?

View 1 Replies View Related

Visual C++ :: Program To Calculate Sales Totals For A General Store - While Loops

Jan 25, 2013

I need coding this project using while loops and cout/cin.. It is suppose to be one while loop for the whole thing and inside of the first while loop is the second while loop for each sale separately.

You have been asked to write a program to calculate sales totals for a general store. Your program will not know how many products each customer will buy, so your program will have to repeat the process until the last product has been entered (use -1 for Product ID to end each sale). After each sale your program must ask if you want to do another sale (Y - continue, N - end program).

At the beginning of the day, the cash drawer has $500 in it. At the end of the program you must display how much money is in the drawer after handling all your sales transactions.

Input
Your program must take the following input:
- Product ID Number (int)
- Quantity for each item purchased (int)
- Cash Received at the end of the sale

Use the following dataset to determine the price and taxability for each item.

First Sale:
Product ID Price Quantity Taxable
101 $65.00 2 Yes
102 $12.50 1 No
103 $24.50 5 No
104 $38.75 4 Yes
105 $17.80 6 Yes
106 $16.50 2 No
107 $42.85 8 Yes
108 $32.99 2 Yes
109 $28.75 1 Yes
110 $51.55 1 No

Second Sale:
Product ID Price Quantity Taxable
102 $12.50 1 No
103 $24.50 1 No
106 $16.50 1 No
107 $42.85 1 Yes
108 $32.99 1 Yes
109 $28.75 1 Yes

Third Sale:
Product ID Price Quantity Taxable
106 $16.50 4 No
107 $42.85 3 Yes
108 $32.99 1 Yes
109 $28.75 5 Yes
110 $51.55 2 No

Calculating Tax
For those items that are taxable, assume a 7.5% sales tax. Be sure to keep a running total of tax for the each sale.

Getting Started
You must use the starter file provided with this assignment.
What to turn in:
- A copy of your source code
- A printout of your program's output

View 2 Replies View Related

Visual C++ :: Blocking Keyboard Play / Pause Button In Windows 8?

Mar 27, 2014

I am writing an application that needs to temporarily disable the Play/Pause button that appears on multimedia keyboards.

Normally, a key can be blocked quite easily by installing a low level keyboard hook (WH_KEYBOARD_LL) where the KeyboardProc intercepts the key (in this case VK_MEDIA_PLAY_PAUSE) and returns a "1" instead of calling CallNextHookEx. I have tried this with other keys (including the Windows key VK_LWIN) and this works perfectly. I also have no problems with this method under Windows 7 where all keys, including VK_MEDIA_PLAY_PAUSE get blocked.

Windows 8 is a different story. When my application has input focus, everything works as expected, meaning the VK_MEDIA_PLAY_PAUSE key gets blocked and no other application responds to it. However, when my application loses focus, my hook procedure gets called (this was verified by sending out a OutputDebugString) but other applications respond to key even though I return a "1". As soon as my app gets focus again, everything is block as it should.

After some investigation, I found that the multimedia keys not only generate keystrokes but also generate WM_APPCOMMAND messages so I added ShellProc (WH_SHELL) hook with the following hook procedure:

LRESULT __declspec(dllexport)__stdcall CALLBACK ShellProc(int nCode,WPARAM wParam,LPARAM lParam) {
// Do we have to handle this message?
if (nCode == HSHELL_APPCOMMAND) {
OutputDebugStringX(">>>>> HSHELL_APPCOMMAND");

[code]....

This procedure is only getting called when my app has input focus. Whenever I have input focus and return "1" the Play/Pause command gets blocked. As soon as I lose focus the procedure does not get called/hooked.

As I have mentioned, the code works for other keys, just not the multimedia keys.

Alternatively, another way of blocking the multimedia keyboards Play/Pause button?

View 6 Replies View Related

C++ :: Does Prototype Of Friend Function Has No Value?

Mar 30, 2013

[URL] ..... Prototype is commented.

[URL] ..... Prototype is included.

both give the correct output. Why?

View 2 Replies View Related

C/C++ :: Getting Error Name Function Should Have Prototype

Aug 25, 2014

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main() {
int i=1,j=2;
float k,l=1.5;

[Code] ...

View 3 Replies View Related

C :: Change Prototype For Generate Fibonacci

Apr 12, 2014

I have written this bit of code for the Fibonacci sequence.

Code:

9 int size=0;
10 int fib[DWORD];
11
}

[code].....

I have tried quite few things and I am trying to change the prototype for generate Fibonacci to... int* generateFibonacci(size). I have been trying to use calloc inside generateFibonacci and then declare a pointer in main that points at the address of the pointer that generateFibonacci returns.

View 9 Replies View Related

C++ :: Type Signature For Function Prototype

Mar 30, 2013

The function im having problems with takes an array where each element is an array of unsigned chars i.e. octals representing a bitmap of one of 95 ASCII code characters and searches through this two dimensional array looking for a match for a predetermined of array of unsigned chars i.e. the bitmap of a predetermined char. If we find the char the function outputs the index in the two-dimensional array where each elem. is an array of octals ELSE it return -1 i.e. when the char is not found.

I have 2 files, one .cpp, the other .h. There is a function named find_char. See INPUT and OUTPUT on line 48 in .cpp file.

The exception im getting is: font2.cpp:23:45:error: invalid conversion from unsigned char to unsigned char(*)[5]

The input type specified for my function prototype corresponding to find_char. If I put just unsigned char it doesn't fix the problem because it's an array parameter i.e. like a call by reference. I've lead myself to believe that the array variable contains a pointer to the first value in the array and so I've made function prototypes that work with a T* i.e. a pointer to type T. Making the function prototype argument unsigned char* i.e. a pointer to unsigned char simply gives me the exception: "invalid conversion from unsigned char to unsigned char*". When I have the argument be 'unsigned char' I get undefined reference to find_char(unsigned char). URL.....

View 1 Replies View Related

C++ :: Switching Function Prototype To Another Type

Mar 29, 2014

This is my code:

#include<iostream>
#include<string>
using namespace std;
int bin2dec(const string binarystring); // Declaration of bin2dec prototype with one string parameter
int main() {
cout << "Enter Q to terminate program.

[Code] .....

Right now the code is in the form of a 'const string binarystring' and were supposed to be able to use 'const char binarystring[]' and for some reason whenever i try to switch it i run into problems when referencing the main function to the int bin2dec(...) function.

I wanted to know if theres a simple way to switch the prototype to an array type of function with [] without changing the entire code.

View 7 Replies View Related

C++ :: Class Prototype - Generic Function

Aug 20, 2014

Let's first take the following class prototype:

#include <ctime>
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
class Debugger;
class Debugger {

[Code] ....

My question is regarding the GetCurrentDebugLevel function above. Ideally I would like to use just one function to get the current debug level of the class, the std::string form would be used to save the "debugging level" in a settings file and the enumerated version would for evaluation purposes throughout the program.

My question is if implementing function prototypes by return value the best way to go or should I do something else?

View 4 Replies View Related

C++ ::  How To Initialize Function Prototype Of Array With Zero

Apr 23, 2014

We can initialize normal function prototype's parameters with zero like this:-

void output(float = 0.0, int = 0);

or

void output(int = 0, int = 0, double = 0.0);

But how do you do the same for a pointer array or simply an array?

Assume that second parameter has to be an array.

I have tried the following and it does not work:-

void output(float = 0.0, int = 0);
void output(float = 0.0, *int = 0);
void output(float = 0.0, int* = 0);
void output(float = 0.0, int[] = 0);
void output(float = 0.0, int []);

But if I skip the default declarations altogether, it works.

like:

void output(float, int []);

or

void output(float, int*);

how can I do it by explicitly writing zero, just like the first cases?

View 2 Replies View Related

C/C++ :: How To Remove (Function Should Have A Prototype) Error

May 22, 2013

#include<iostream.h>
#include<conio.h>
int main() {
setcolor(BLUE);
setbkcolor(yellow);
cout<<"the text in blue colour with yelow background";
getch();
return 0;
}  

it keeps returning the same error always in my turbo c++ compiler . What is the correct program for changing background colour and text colour ...

View 1 Replies View Related

C :: Prototype For A Function Accepting Variable Arguments

Dec 6, 2014

what should be the prototype for the following function.

Code:void addition(int x, ...);

I am getting compilation errors. I have written the prototype as :

Code: void addition(int, va_list);

View 3 Replies View Related







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