C/C++ :: Program To Make CMD Stop Without Using Getch Function
Mar 30, 2013Program in c++ that if i ran it the cmd window will stop without using getch statement and conio.h header file, or how ?
View 7 RepliesProgram in c++ that if i ran it the cmd window will stop without using getch statement and conio.h header file, or how ?
View 7 RepliesI was trying to make a tic tac toe game where the user can play against the computer
It s in borland c++ and not in c++ 11 so i wanted to convert it into c++11. My program shows error since there is nothing called conio.h in c++11. Hence I want to know if there is any alternate keyword gor the function getch() so that i could ask the user to press [ENTER].
Code:
#include<process.h>
#include<stdlib.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
int usbox,i,j,nandu=0,result,cusb,cobox,r,d;
int playl=0;
char copybox[10];
[Code] ....
How can I make fgets stop reading when it reaches a new line? Right now it will read the new line and continue until the buffer is full. I was thinking something like this.
Code:
while(fp!='
'){
fgets(password, 256, fp);
}
I want the numbers to be put into the array until it hits a new line. Maximum number of numbers is 1000. What can I replace that while loop with to stop it from reading further into the input file?
Code:
while (input != '
'){
for(i=0; i<1000; i++)
fscanf(ifp, "%lf", &auctions_prices[i]);
My assignment is to create a C++ Program to find the sine of a number without any library other than iostream by using Taylor Series:
sin (x) = (x/1!) - (x^3/3!) + (x^5/5!) - (x^7/7!) + (x^9/9!) ...... (x^n/n!).
Here is what i have done till now:
#include <iostream>
double fact (int f); //declaration of factorial function
double power(double x, int y); //declaration of power function
double sin(int x); //declaration of sine function
//double cos(int x); //declaration of cosine function
//double tan(int x); //declaration of tangent function
[code]....
I am asking for input for a char by using the _getch() function. The thing is that when a key is pressed multiple times it screws the program because it executes every single key that is entered.
I am asking for the user to enter a letter that will determine an action to be used in battle, like attack, magic, "use item", etc.
char option;
cout<<"Enter your choice for battle: ";
option=getch();
if(option=='a')
//Executes an attack
else if(option=='b')
//Opens magic menu
else if(option=='c')
//Opens item menu
Suppose the user enters a character, then the program executes an action by the enemy monster. This is where the problem arises, if the user entered multiple keys or if he enters input during the time the monster attacks, the next time it is the user's turn it will execute the first attack automatically because it keeps reading the input.
I want to know how to cut it off, so that it doesn't ruin the program like that.
If I wanted to add an emergency stop to an elevator programme should I use an if statement? Eg
Code:
If (emergency stop) {
Void main();
}
Or something along those lines?
My program has a goto label in it and when the program is not instructed to goto the label, it does. When control goes to the line that it is on, even if no where does it say to execute the label's content, it does execute it.
View 6 Replies View RelatedI am new to c++ programming, and I wrote this program. It runs perfectly but the problem is I want the program to stop If I entered letters other than A,B or C
The code as follows:
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std ;
int main() {
// Deceleration Statements
[Code] ....
#include <iostream>
using namespace std;
int main() {
[Code].....
It's a tic-tac-toe program. I haven't finished doing everything I need to for the project, I'm just trying to get certain parts working as I go.
Anyway, my problem: The program will print the board and ask the first player which square they want to mark. Then it will print the updated board, print the question for the second player to input their square choice but not actually stop to let the user enter anything. Instead it prints the board again and then prints the question for player one again -- this time stopping to let them type in their choice.
Here's my code:
#include <stdio.h>
// Function prototypes
void printBoard(char board[3][3]);
int main() {
int quit = 0;
// Loop so game continues until player quits
[Code] .....
And it looks like this when I run it, as an example:
-------------
| 1 | 2 | 3 |
-------------
| 4 | 5 | 6 |
-------------
| 7 | 8 | 9 |
-------------
Player 'C' enter a square: 5
-------------
| 1 | 2 | 3 |
-------------
| 4 | C | 6 |
-------------
| 7 | 8 | 9 |
-------------
Player 'U' enter a square:
-------------
| 1 | 2 | 3 |
-------------
| 4 | C | 6 |
-------------
| 7 | 8 | 9 |
-------------
Player 'C' enter a square:
I am writing a program which creates a set of coordinates that when plotted will reveal a syastro crescent moon character. If you imagine plotting a crescent moon as two circles with different radius, where the overlap will create the shape. The problem I am having is how to just plot where they overlap ( ie the crescent moon part) and no the rest of the circles. How can I impose a boundary to stop the program creating coordinates I dont want. My first attempt is an if else loop.
View 1 Replies View RelatedI want to fix this code. The program must accept 7 values or stop it when you type s. The code not only couts the element, but also some other random numbers.
Code:
#include<iostream>
using namespace std;
int main() {
int numb[7];
int i;
char s;
for (i=0;i<=6;i++)
[Code] .....
My code is given below:
cout<<"1. runtim";
cout<<"2.tims";
cout<<"Your selection will be automatically neglected within (function to be inserted for time ) ";/* insert timer here */
cout<<"What kind of process u need to do";
.
.
.
.
I have 2 questions
1.the timer function has to be such that when any key is pressed in between the specified time its has to stop its counting and go to the nest line and functions . i checked sleep function but if any key is pressed its does not break out of the sleep program and execute the next command
2.and if the timer has completely finished running then it has to skip few lines and execute the program .
I was given a task to convert infix to post fix using both linked lists and stacks in the code so this is what i have written but the problem is it is giving me same error at three different places "missing function header(old style format?)
#include <iostream>
#include <string>
using namespace std;
const int size = 100;
class stack{
private: // Declare a structure for the list
[Code] ....
Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {
[Code].....
But when I try to call it, trying to copy my previous method,
glutKeyboardFunc(Player1.playerControls);
I get an error
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.
I would like to know how can I make a simple program .exe so that I don't have to open it through code blocks every time.
View 2 Replies View RelatedI'm trying to write a program for a lab, I know how easy it is but cant see to crack it.
I need to make a program using while or for loop.
I must have the user type a number, for an input value an output value but then do it again several times but without it going on forever asking again and again.
i need to write a program that when run makes another exe file . Eg: make a program named 'sxes' and compiled it. When i execute or run sxes a new exe file named 'new01.exe' is created. This new01.exe when executed must input two numbers and add them and print output. I want to write a program same as installer file .
View 11 Replies View Relatedhow to make the hospital program
View 1 Replies View RelatedHow to make a loop so program never end, it end only by typing "EXIT"
View 1 Replies View RelatedIm suppose to make a "poor mans" variation to the Sort function built into unix. The program is suppose to read in a file and sort the contents of the file. So its a variation of the Unix Sort feature. I have remade the readLine function we were provided so that it doesnt use fgets. where to go from here, Not sure on how to make a sort function. Here are the reqirements of the program:
Code:
• Re-implement the readLine() function so that it no longer makes use of fgets(). Instead,
process the input on a given line character-by-character.
• Provide code which will create a data structure similar to argv to hold all of the words to be sorted. Use malloc() to ensure that each entry has just the required number of bytes needed to store the words. The final entry in your array should be the NULL pointer.
• Implement a sort() function which will rearrange the words in sorted order. To swap two words in your array, note that only a pair of pointers need to move. The strings themselves, once established, will never move. Heres what i have:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINES 1000 /* maximum number of reminders */
#define WORD_LENGTH 10 /* max length of reminder message */
[code]....
I will post the entire code at the bottom. Its running fine right now but This part in the menu function I need to make as a separate function. My problem is when I make it into a function by itself I have to declare and initialize the grades A,B,C,D,F how can I do that when I can't make them equal 0 because it has to keep track of how many of each letter grade.
Code:
//Count letter grade
if(ave >= 90)
++A;
else if (ave >= 80)
++B;
else if (ave >= 70)
++C;
else if (ave >= 60)
++D;
}
[code]....
I would like to know if there is a way to make a function non overloadable. My idea is to keep it private in the class so that it will be impossible to overload the function in a derived class.
But if in the base class (the one that holds the private function) I also have a public or protected function (let's call it plf) to manage the private one (let's call it prf), and in the derived class I create a function with the same name as the private base class function (prf) that calls for the public base class function (plf), I am wondering if there won't be a conflict between both of the same-named (prf) functions?
Assuming the prf function of the derived class is not an overload of the prf function of the base class (because the last one is not visible).
I am looking to make a program for C++ that has a GUI other than command prompt. The program I am trying to create will ask certain questions and display the results at the end after all questions are asked and have 2 copies of the results one over the other that can be printed as a receipt. Basically I am wondering can I do this using C++. Also I want another GUI other than command prompt as well. Something close to what windows uses if possible.
View 5 Replies View Relatedi wanna no if i can make the program generate a different number everytime you guess the number right and want to play again. it always generates the same number
#include <iostream>
#include <ctime>
#include <cstdlib>
[Code].....