C++ :: Case Statement Not Working?

Mar 6, 2015

I have this case statement that is not performing as expected. For some reason ASE_OK and ASE_NotPresent both print out. Why is this? ASE_OK is a return value of 0 while ASE_NotPresent is -1.

Code: // Try to create the buffers and store it
switch (theAsioDriver->createBuffers(info, numChannels, bufferSize, callbacksInfo)) {
case ASE_OK:
std::cout << "ASE_OK";
input->bufferSize = output->bufferSize = bufferSize; // Buffer size is stored in both input and output
case ASE_NotPresent:
std::cout << "ASE_NotPresent";
errorMessage = "Could not find input or output devices.";
return NO_DEVICES_FOUND;

[code]....

View 3 Replies


ADVERTISEMENT

C++ :: Case Switch Statement Half Working?

Jan 31, 2015

was making a somewhat of a Binary to Hex convertor but only 10/15 cases work and the non working are in the middle; 0010, 0011, 0100, 0101, 0110, 0111;;

// Test Code.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
int main(void)
{int A;
cout << "Enter the binary starting with the MSB

[code]....

View 5 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 :: Switch Case Statement Does Not Execute

Feb 11, 2013

Im going through a C tutorial and im going to create a Database as part of the course. Im just in the very beginning of the project so its a very simple program so far.

Code:

#include<stdio.h>
main(){
/*Variabler for att lagra information om skiva*/
char title[200];
char artist[100];
int tracks;
int price;

[Code] ....

The first switch case statement takes me to the menu of choice, 1 or 2. However, chosing menu option one and trying to input a title or artist name, the program crashes.

Next, going into menu option 2 and then trying to print out, for example, title nothing happend. The process just ends.

Again, im sure this simple prototype is full of errors ....

View 1 Replies View Related

C++ :: Switch Statement Without Writing Each Case

May 28, 2014

I was just wondering if a switch statement can work without writing each case, for instance:

{ int age;
age=18;
while (age!=0) {
cout<<"Enter age :"<<endl;
cin>>age;
switch (age) {

[Code] ....

It works only for values specifically entered as a case, for instance if you enter 5 or 15 , it says bicycle, but if you enter anything inbetween it goes to default. Same with 18 and 100. It can't possibly be that you have to enter

case 19:
case 20:
case 21:
case 22:.......up to 100 to include all possible cases.

View 7 Replies View Related

C/C++ :: Switch Statement Always Prints Default Case?

Feb 25, 2014

#include <stdio.h>
int main () {
int num;
char choice;
printf(" Welcome to a Menu-Demo Program
Please select one of the following actions
R - Programmers Rock!
F - Programming is Fun!
G - Geeks Rule!
X - Exit program
Selection ==>__ ");
do{
choice = getchar();
switch(choice)

[code]......

I am currently writing a simple program that utilizes switch statements. When I run my program, it always displays the message for the default case.

View 4 Replies View Related

C/C++ :: Switch Case Statement Not Returning Correct Values

Mar 21, 2015

My code is supposed to read a five to four digit code of a resistor from a file and determine the resistor's nominal, lower and upper tolerance values. I have inputted my file's first resistor code as a string so I could run tests on it but the problem that occurs is that a get the wrong values from my switch-case statements. I have put printfs after the function call to see what the values were and they turned out wrong. If I could get my return values to be right then I could be on my way coding.

#include<stdlib.h>
#include<stdio.h>
double bandNum(char x); // function prototype that will read the resistor value for the first, second and possibly third band
double bandMult(char x); // function prototype that multiplies the resistor by some value of 10
double bandTol(char x); // function prototype that the tolerance of the resistor is multiplied by

[Code] ....

View 5 Replies View Related

C :: If Statement Not Working

Oct 21, 2013

Well for some reason this doesn't work.

Code:

#include <stdio.h>#include <ctype.h>
int main(void)
{
int lottoNums[150];
int num;

[Code]....

View 13 Replies View Related

C++ :: Switch Statement Is Not Working?

Aug 16, 2014

okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine

Code:
#include<stdio.h>
main ()
{
//passcode part (passcode is 1234)

[Code].....

View 5 Replies View Related

C/C++ :: Char Condition In If Statement Not Working

Feb 3, 2015

I'm trying to get an if/else statement to work using a character condition, but it is a no-go. After I input either a 'y' or 'n', the program just sits there until I press 'Enter' again, at which point it ends. It never actually goes through either of the 'if' statements. At first I only had a single '=' in the condition, but I found that that was wrong. When I corrected it to '==' it still didn't work. I also tried clearing the buffer by adding a 'getchar()' at the beginning of the program, but that didn't work either.

#include <stdio.h>
#define std_rate .8855
int main(void) {
char ans;
int counter = 1, euros = 5;
double dollars = 0, ex_rate;

[Code] .....

The compiler (Visual Studio 2013) requires me to use 'scanf_s' instead of just 'scanf' for some reason, and if I don't have two 'getchar()' commands at the end, then it won't stay open long enough for me to see the results.

View 2 Replies View Related

C/C++ :: Switch Statement Not Working In Functions

Nov 22, 2014

The switch statement is giving me trouble. Worked fine in the main, but when I had to put it in separate functions per my professor, I had several issues. I guessing I am not calling the function correctly. Our group worked on it but could not find a solution to fix the switch statement.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h>
using namespace std;
//function prototypes
int menu(); //function to show main menu
void Seating_Chart(); //function to show seating chart

[Code] ....

View 2 Replies View Related

C++ :: Cout Statement Not Working - Program Outputting Zero For Variable

May 20, 2013

Why is my program outputting zero for the variable pop?

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

//capture data
cout << "Enter the world's population: ";

[Code] ....

It's obviously not std::cout, but I'm thinking its the way I'm operating on long?

View 5 Replies View Related

C++ :: If Statement To Read Number Negative Or Positive Not Working

Nov 10, 2014

So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.

#include <stdio.h>
#include <iostream>
#include <iomanip>

[Code].....

PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.

View 2 Replies View Related

C :: How To Get Upper Case And Lower Case Equal

Feb 18, 2015

I just dont know how to get my upper case and lower case equal...heres the program: Write a program to calculate utility cost for ACME UTILITY COMPANY. The company has 3 types of customers (R) residential, (C) Commercial and (G) government. Customers are billed based on the number of kilowatts used and they type of customer they are (R,C,or G).

Residential cusstomers are charged 0.25 cents per kilowatt hour for the first 500kw used, and 0.35 cent per kwh for all kw used over 500.Commercial customers are charged 0.22 cents per kilowatt hour for the first 999kw used, 0.29 cents per kwh for all kw used over 999 kw up to 1999 and 0.45 cents per kwh for all kilowatts used greater than 1999. Commercial customers that use over 2000 kw are charged a special surcharge of 100.0 in addition to the regular charges.

Government customers are charged 0.34 cents for the first 1500 kwh used(<=1500). 0.30 cent for the next 1000 kwh(1501-2500) and 0.25 cents for all kwh used over (>=2501)

in addition residential customer are charged .5% tax on the cost utilities while Commercial customers are 5% tax on the cost of utilities not including the special surcharge Government customers are not charged a tax

Code:

#include <stdio.h>
#include <math.h>
int main(void)
{
int R;
int ct;
int kwh;
int taxes;
int surcharge;
int charge
}

[code].....

the program should quit with Q and calculate the amount owed, utility charge, and surcharge

View 8 Replies View Related

C++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C :: Using Or Inside Case Arguments

Nov 6, 2013

I would like to choose same case for multiple switch conditions.

For example:
Code: switch(choice) //''if choice ==0 or choice ==1, chose same case''
{
case (0 || 1):
{
//execute steps
}
break;
default:
{
//execute steps
}
break;
}

The '||' inside case does not have the desired effect (although it compiles fine). How can I do it without using if-else statements.

View 1 Replies View Related

C# :: Switch Case Variable Scope

Jan 31, 2014

Ran into something today that does not make sense:

This compiles: Code: int x = 5;

switch(x) {
case 0:
{
int value = 5;
}
break;

[Code] ....

Ok so it doesn't like int value = 6 b/c of int value = 5 for case 0. However since the value in case 0 is declared within the brackets one would think it has case scope.

So I tried this:

Code: int x = 5;
switch(x) {
case 0:
{
int value = 5;
}
break;

[Code] ....

Now it doesn't like it b/c value has not been declared in case 1:. These two conditions cannot possibly be both true at the same time. You cannot disallow the declaration of value in case 1 b/c it interferes with value in case 0 and at the same time disallow me to use value from case 0 b/c it is not in scope. If it was not in scope then theoretically I should be able to declare value in case 1.

Both MSVS 2012 and 2013 exhibit the same behavior. I checked the standard and it is unclear on the matter.

View 7 Replies View Related

C :: Program Keeps On Crashing When It Finishes Case 1?

Oct 18, 2013

The program keeps on crashing when it finishes case 1

View 5 Replies View Related

C++ :: Case Scope In Switch Statements

Dec 16, 2013

Is it's scope confined to that single case?

char ch;
switch(ch) {
case '1':
using namespace common::section1; //only this case??
break;

[Code] ....

View 8 Replies View Related

C++ :: Getting Error - Case Value Has Already Appeared In Switch

Dec 11, 2014

I keep getting the error "case value has already appeared in this switch" how do I fix this?

switch (selection) {
case 'A' || 'a':
aFunc(Houses);
break;
case 'B' || 'b': //The error is here
bFunc(Houses);

[code].....

View 3 Replies View Related

C++ :: Comparison Of Two Strings (case Insensitive)

Apr 27, 2013

bool simpleQuestion::checkAnswer(string guess) const {
for (int i=0;i<qAnswer.length();i++)
if (qAnswer==guess)
return true;
else
return false;
}

This is my code and what im trying to accomplish here is making the comparison of the two strings (qAnswer & guess) case insensitive. I know i need to loop through each character of each string and for each character i can use toupper and every char in each string will become uppercase and therefore case insensitive. However, im not sure how to go about this; if any technique used to loop through each character of the string and how to use to upper.

View 2 Replies View Related

C++ :: Change First Letter Of Each Name To Upper Case?

Oct 2, 2013

I can get the first letter to change if there is only one word. But if there are two words it wont change and display the second word's first letter and I'm not sure why.

#include <iostream>
#include <iomanip>
#include <cstring>

[Code].....

View 3 Replies View Related

C++ ::  switch Case With Enum Types

Jul 4, 2014

I'm trying to convert the enum type {PG, R, G, PG-13, etc.} to strings so i can use it in cout statement but no matter what i put inside switch(), the compiler keeps saying Error: expression must have integral or enum type. What am I doing wrong exactly?

Movie covert_rating(Movie r) {
switch (r) {
case PG:
return "PG";
break;
case R:
return "R";

[code]....

View 4 Replies View Related

C/C++ :: Stopping Case For Asterisk Pattern?

Dec 1, 2014

So, I'm going to write a recursive function for a asterisk pattern but I'm stuck figuring out how to create a stopping case for it, better yet, I'm unable to describe the pattern completely.

*
**
-*
****
--*
--**
---*
********
-----*
-----**
------*
-----****
-------*
-------**
--------*

( - represent white spaces )

What I've been thinking:

* Every odd row has 1 * with 1 incremented white space

* Every "pair" of asterisks equals 8 total (EX. 8 one pair *'s, 4 two pair *'s, 2 four pair *'s)

Unfortunately, that's all I got. how I can represent this as I function. Once I figure out what my stopping case should be, I think I can do the coding on my own.

View 1 Replies View Related

C/C++ :: How To Compare Strings Ignoring Case

Oct 29, 2014

It should report whether or not, ignoring case, they are the same.

#include <stdio.h>
#include <string.h>
using namespace std;

[Code].....

View 1 Replies View Related

C/C++ :: Initialization Of Fin Is Skipped By Case Label

Jan 28, 2015

This program was running at first but when I started to change the couts and cins to fouts and fins (in order for them to be save in a file directory), it shows a lot of errors such as:

initialization of 'fin' is skipped by 'case' label
'std::ifstream fin': redefinition

Here is the code of the program:

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;  
struct file{
    int fnum;
    char fname[50], lname[50];

[Code] ....

View 1 Replies View Related







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