C/C++ :: Program Closes When Using Any Number In Switch

Feb 17, 2015

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]....

when running the program it closses after the switch.

View 2 Replies


ADVERTISEMENT

C++ :: Program To Determine Number Of Inputted Riders And Closes When Input Is -1?

Jan 16, 2015

I seem to be having a logical error but can not find the sources.

#include <iostream>
using namespace std;
int main() {
int student = 0;
int adult = 0;

[Code] ....

View 1 Replies View Related

C/C++ :: Infinite For Loop - Program Just Closes

Feb 10, 2015

So I learned how to make a basic for loop and I decided to try my best to make an infinite one. Every time I run it, it doesn't say anything and just closes. Visual Studio doesn't say there's anything wrong with my code.

Here's the code

#include <iostream>
#include <conio.h>
using namespace std;
int main () {
int d = 9;
for(int k = 10; k < d; k = k +1) {
cout << "For loop value = " << k << endl;
getch();
} }

View 4 Replies View Related

C++ :: Program Compiles / Runs But Closes Right Away When Finished

Oct 15, 2013

Program compiles and runs no problem but closes right away when finished.

Heres the code:
Code: #include <iostream>
#include <cmath>
using namespace std;
double calcDistance(double,double, double, double);
float calcKilometers(float, const float) ;

[Code] ....

View 3 Replies View Related

C :: Process For Printing Number Of Times A Switch Case Has Been Used?

Sep 20, 2013

I want to have one case of my switch statement to print out how many times the user has chosen other cases in the switch statement. Such as "You have pressed 2 6 times and 4 3 times."

View 3 Replies View Related

C++ :: For Loop - Code Puts Out Switch Statement 5 Times With Random Number

Jan 26, 2014

I am writing for loop with a switch so that scores can be inputted in by a judge. The issue that I am running into is that I will put out an the text then the test happens and the code puts out the switch statement 5 times with random number. Here is what I have written.

Code:
int main() {
int diver;
int option;
int Judge;
cout << "Enter Divers Name:";

[Code] ....

View 4 Replies View Related

C/C++ :: How To Use Switch Statement 2 Times In A Program

May 10, 2012

How can we use switch statement 2 times in a program?

View 2 Replies View Related

C/C++ :: How To Put All Questions In One Program By Using Switch Statement

Mar 22, 2013

How to put my all assignment questions that are 6 in number in one program by using switch statement ?

so if a user wants to see any question by choice!

View 1 Replies View Related

C :: Use Switch Case As A Menu To Switch Between Patients

Dec 30, 2014

I am trying to make a program which manages the data of 5 different patients (its an uni assignment), and i want to use a switch case as a menu to switch between the patients. All other functions (as for example putting the infromation on a file) work, but i cant figure out to bring the switch to work. First it asks for the number of the patient which should be worked with, this works perfectly, but afterwards changiung between the persons doesnt work as thought. It should ask everytime after it switches to one patient (i removed some functions to make it easier to read) and then asks to which it should jump next. If i put the number of one case (lets say 3) it just stops the program.

********Example:
user@pc ~/wherever $ ./program
current variables:
jo = 2
a = 0
1 //the entered number
The variable a = 1
patient 1
Enter the number of the next patient2
// and then it closes
**************

The same thing happens if i compile an example code from a book, it writes the first case and then stops.

I looked already through the forum but didnt find a person with a similar problem, maybe i didnt dig deep enough.

I am running Linux Mint 17 and use gcc as compiler.

Code:

include <stdio.h>
#include <stdlib.h>
int a=0;
int jo=2;
int main(void){
printf("current variables:
jo = %d
a = %d

[Code]...

View 13 Replies View Related

C :: Blackjack Program - Multiple Choices In Switch

Dec 6, 2014

I'm writing a Blackjack program where the user can choose to Hit(H) or Stand (S). I would like them to be able to use upper or lower case letter for this. My code doesn't seem to work right for my Stands.

Code:
char choice;
do {
choice = 0;
while (choice < 1) {
printf("

[Code] ....

View 3 Replies View Related

C++ :: Menu Program As Switch-Case Structure

Feb 13, 2015

I tried to write a menu program as a switch-case structure with a separate function for a switch-case structure itself. The outcome for it currently is an undesired one

Code:

#include <iostream>
using namespace std;
int menu(int answer);
int main()

[Code].....

The output I get is one where it's just an infinite loop of "Bad choice! Please try again later.".

View 7 Replies View Related

C++ :: Write A Program That Has A Menu With A Switch Statement?

May 4, 2014

I'm trying to write a program that has a menu with a switch statement. I'm getting "case label'1' not within a switch statement" and subsequent errors for the other two choices and the default.

int main(){
int choice;
Matrix A,B,C;
cout <<"What would you like to do? "<< endl;

[Code]....

View 2 Replies View Related

C++ :: Switch Structures - Program To Arrange Values

Mar 5, 2012

Write a program that accepts three values (int) from the keyboard into three variables a, b and c. After loading the variables, your program will arrange the values into a, b, and c, so that a contains the larger, be the next and c the smallest.

You can use any other variables in addition to a, b c, as you see fit.

You will have to use some variation(s) of the if construct.

There are many ways to program this, but your challenge will be to achieve this without doing all possible comparisons. In fact, three comparisons woudl be enough, if you , for example, determine the largest number first, and keep track of its position in some way , so you can compare the other two.

I think I might use a code similar to the one below.

switch (expression) {
case constant1:
group of statements 1;
break;
case constant2:

[Code] ....

View 14 Replies View Related

C++ :: Switch Case - Program That Calculates Students Grade

Apr 18, 2013

Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.

#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;

[Code]....

View 6 Replies View Related

C++ :: Program Using Switch Statements To Pass Multiple Functions

Oct 1, 2014

I am returning area from areaCircle(), but do not know how to print it in main. I know this program has lots of errors, two cases that I have listed.

Not sure how to properly list multiple function calls in a switch statement, and how to print one's return from main.

int main() {
char choice;
double area;
showMenu(choice);
switch (choice) // If input is C, use getRadius, areaCircle and count, then print the are
{
case 'C': void getRadius(),double areaCircle(), void count(bool display = false);

[Code]...

View 5 Replies View Related

C++ :: IDE Closes When Alt F9 Or Ctrl F5?

Sep 11, 2014

I've recently downloaded c++ ide for windows 8(dos boxed version).

Every time i try to compile or run any program. It simply closes down?

View 2 Replies View Related

C :: Snakes And Ladder Program - Dice Function To Switch Between Players

Mar 25, 2013

I am writing a snakes and ladder program and I'm almost finished, but I am struggling with the dice to work in the way I want it to work. I want the dice to work like this :

Before each player throw the dice they must start at 0.
Each player must throw a 6 on the dice to move on the board.
If a player threw a 6 on the dice, that player can throw again.

But I ended up with two seperate dice, one for each player (game is only for two players).And when I run the program, both players don't start at 0. And when I throw the dice, both players move at the same time but with different values.

If one of my players threw a 6, they just keep on throwing until someone wins the game. I tried to use a switch and if statements but I couldn't get it right. And so I did this :

Code:
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#define SpaceBar 32// 32 is an ASCII value for a spacebar

[Code] ....

View 5 Replies View Related

C++ :: CMD Closes After User Input

Jun 7, 2014

I'm trying to make a simple program that accepts user input, simple stuff. When the user (me) enters a number to be sent to the console and i press enter so it accepts the data, it closes the command prompt and thus ending the program. I just need to find a key that i can use to continue but doesn't close cmd.

View 5 Replies View Related

C# :: Closing MDI Children Closes Main App?

Mar 14, 2014

The following not only closes the MDI children, but also the form I set to be an MDI container.

private void close()
{
Form[] childArray = this.MdiChildren;
foreach (Form childForm in childArray)
{
childForm.Hide();
}
}

View 5 Replies View Related

C/C++ :: SDL Window Auto-Closes When Image Changes

Jan 22, 2014

Background: I'm making a small game using CodeBlocks and SDL. All of the code resides in a class named Game - the only thing running in Main is the creation of the Game object and the class function execute(). So far, I've made a Start Menu with three clickable buttons. I'm in the midst of making one of the buttons - Load Game - change the game screen to the Load Game menu. Basically, when the user clicks the button, the image on screen changes according to the button they click.

Issue: After successfully making the Load Game button change the image on the screen, I found that the SDL window mysteriously closes out several seconds after the image change. What is causing this - the window stays on perfectly fine until the background image is changed and the only way to break the loop is for the player to click the x on the window. I've gone over the code several times and haven't found anything that might be the cause.

Code:

Game.h file
#ifndef GAME_H
#define GAME_H
#include "SDL/SDL.h"
#include "SDL/SDL_ttf.h"
#include <iostream>
#include <cstdlib>

[Code] ....

Output:
- Window with an Start Menu image and a button with the words "Load Game".
- If user clicks the X on the window, the window closes.
- If user clicks "Load Game" button, Start Menu image changes to Load Game image. After about seven seconds, the window automatically closes out. This isn't supposed to happen.

View 5 Replies View Related

C++ :: Execute Function If User Closes Console

Feb 17, 2013

I would like to implements something in my code that clears the value of my variables when the user closes the console. How to do that or the program clears the values automatically?

View 3 Replies View Related

C++ :: Calculate Wages For Employees - Loop Closes Before Finishing

Dec 11, 2013

I'm writing a code that's suppose to do a payroll for my intro cs class. At first it was working fine until I had to add the part that made sure a user couldn't enter a wage value below $6.00 and now it stops the loop right after that part for some reason.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int const HR = 7;

[Code] ....

View 2 Replies View Related

C :: Program That Allow User To Enter A Number N And Print Nth Prime Number

Nov 3, 2013

I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....

EXAMPLE

user enters 55

printf("The 55th prime number is %i", variable");

View 1 Replies View Related

C/C++ :: Program To Find Number Of Digits In Number?

Aug 20, 2014

In the c pgm to find number of digits , if I am giving 001 as the input number ,why I am not getting the no. of digits as 3?

View 2 Replies View Related

C++ :: Program To Display Even Number From 100 - 200

Jan 23, 2014

i wrote this program to display even number from 100-200. But visual c gives me this error with undeling the "a" in if statement. Error1error C2106: '=' : left operand must be l-value

#include<iostream>
#include<conio.h>
using namespace std;
void main(){
for(int a=100;a<200;a++){
if(a%2=0)
cout<<a<<endl;
}
_getch();
}

View 1 Replies View Related

C++ :: CPP Program To Check Whether A Number Is Palindrome Or Not?

Feb 12, 2014

I could not find the mistake in this program....

Code:
//cpp program to check whether a number is palindrome or not
#include<iostream.h>
#include<conio.h>
//the class
class palindrome

[Code] ....

View 4 Replies View Related







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