C :: If Statement Not Working
Oct 21, 2013Well for some reason this doesn't work.
Code:
#include <stdio.h>#include <ctype.h>
int main(void)
{
int lottoNums[150];
int num;
[Code]....
Well for some reason this doesn't work.
Code:
#include <stdio.h>#include <ctype.h>
int main(void)
{
int lottoNums[150];
int num;
[Code]....
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]....
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].....
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.
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] ....
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]....
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?
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.
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]....
Whenever I put my dll files in the same directory as my main.cpp and use this code, Code: g++ main.cpp -L. -lMyDll it works.
but if my dll files are in the other directory, Code: g++ main.cpp -L/myDlls -lMyDll it won't work. Why is this not working?
i am currently trying to get SDL working with C language.I am using Cygwin and Sublime text 2.I know and understand general programming, however i am trying to understand how to get SDL working with a file i create i.e test.c. i know to include which i have downloaded
#include <SDL.h>
where do i add the libraries so that i can use them in my program?
I am writing an irc bot in c++ on linux mint, and its not connecting right for some reason. anyways, heres the link: [URL].... . it was connecting to quakenet before I added the functions, but now it just says connecting... and then quits.
View 12 Replies View RelatedI'm learning network programming and I've decided to program a simple c++ irc bot. I'm able to connect to server and send commands. But when I try to receive and show message from server I first get a few lines, like "Please, wait, while we process your connection" or "Found your hostname". And then I start to get a ton of information about the server. Here is the whole class:
header file:
#pragma once
#include <WinSock2.h>
#include <WS2tcpip.h>
class bot {
public:
bot(char *_server, char *_port);
~bot(void);
[Code] .....
Link to whole visual studio project: [URL] .... Am I doing something wrong during the IRC connection? Or I didn't understand how networking work?
When inserting elements in a set it should only insert unique elements but I get duplicates too.
Code: #include <iostream> // cout
#include <algorithm> // unique, distance
#include <string>
#include <iterator> // std::back_inserter
[Code].....
Code:
#include <stdio.h>
int main() {
int m,c;
for(c=0;c<100;c++) {
m = c % 10;
printf("%d ",m);
}
return(0);
}
When I run this code in my compiler, I get the first nine or ten numbers, and then after that it just spells out the letters in my name in different sequences over and over.
I'm trying to write a code that will
1) Generate a series of numbers
2) Write those numbers onto a txt file and
3) Read only the odd numbers out of the txt file.
I have 3 functions besides main that do each of the objectives individually and when separate they work just fine. But when I put them together for some reason the third function is never started. Also when I rearrange the 3rd function infront of the 2nd (since i have the txt file already saved) it works but I get an error when trying to close the txt file. It is the same close function that I'm using when first creating the txt file as well.
Here is the code
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
}
[code]....
I need to find out all the possible equations which are same of a given equation. For eg. a+b+c-d and b+c+a-d are same. So if the user inputs a+b+c-d then the output will be all the possible equations that can be formed from the given equation, viz:
a+c+b-d
c+a+b-d
-d+a+c+b
etc
i.e the program should rearrange the operands and operators in such a way that it should give the same result.
I have been coding this 2D physic engine for quite some time, I work on the many part of these 2 axis ( x and y ) in the same manner is just that one is an x and one is y
So there is a lot of duplicate code
If there is a bug in one part I have to fix the other axis too which becomes a hazzle because I have to fix the duplicates too. The sample code from my program
for( auto it =bodies.begin(); it != bodies.end(); ++ it ){
sf::Vector2f velocity = it->getVelocity();
if( velocity.x != 0 ){
// do some friction force calculation
[Code] ...
It is even more of a hazzle when I work with 4 quadrant, I have 4 duplicate code each ... How do I write a function for both axis ?
My SDL app which i made in visual c++ works properly on my pc, but it does not even starts on other computers. I have pasted all the required .dll files in my debug folder along with the pictures and sounds.
View 4 Replies View RelatedThis while statement is not cooperating and I am not really sure why. I tried to say while not equal to true and later false, but both produce a never ending loop. I know I posted this before and I got several comments back about different issues with this program. However this question is specific about the while statement.
Code:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
[Code] ....
I'm having a really dumb moment and I cant seem to remember how an if statement works, with only the variable name as the condition..
Code:
if(var){
//then do something
}
how would i got about making an if statement for an array so it prints what u enter
Code:
example:
struct input{
float peopleseen;
float creditrate;
char insurprov[12];
[Code] ....
When I do this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;
[Code] .....
But when I do this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;
[Code] ....
Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?
I was wondering how you would put this if else statement to a switch statement.
void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;
[Code] ....
i am trying to make a ticktacktoe game. I made a simple one with no ai but i decide to add an option to play against computer. And i code like that(i know this is really bad):
/*
Name: TickTackToeFinal
Copyright:
Author:
Date: 26.06.13 20:41
Description:
*/
#include <iostream>
#include <string>
[code].....
when i run the game its always play randomly(last if statements in bilgisayar functions.
not:bilgisayar means computer
zor means hard
orta means medium
kolay means easy
oyuncu means player
tur means round
oyun means game
I seem to be having a bit of problem with my if statements in a for loop.
My code involves asking the user for the name of an element (chemistry), searching a text file line by line for an element that matches the input, and outputting other information regarding that element.
One line of the text file looks like this: Helium,He,2,4.00
I've tried running the code without the if loop and it outputs normally (If I ask it to output elementname[0] it will output the first element Hydrogen, which is correct.) but I am not sure what goes wrong when I add the if statement. For some reason, it always follows the "else" statement (It always outputs Invalid search even when I input the right elements).
const int ELEMENTS = 118; //number of elements
ifstream File;
string elementname[ELEMENTS], atomicsymbol[ELEMENTS], atomicnumber[ELEMENTS], atomicmass[ELEMENTS];
string elemname, atomsym, atomnum, atommass;
string search;
[Code] ....