C++ :: Keep Getting Wrong Results With Char And Scanf

Nov 12, 2013

Code:
#include <stdio.h>
int main(){
unsigned char x, y=10;
scanf ("%c", &x);

[Code] ....

If I take out scanf and assign x a value then it works, but if I enter, for example, 10 into scanf it comes up as 234 rather than 100.

View 13 Replies


ADVERTISEMENT

C :: How To Scanf To Integer Or Char

Feb 6, 2014

I have to make a program for school to evalute poker hand.I am not asking about the logic of the program,I am asking because I have to take the input from the console,five lines which can be the cards 2,3,4..10 and the problem is with J,Q,K,A ,because I dont know how to tell scanf to expect integer or char ? If I type J,Q,K,A the program crash ,

View 1 Replies View Related

C :: Getting Char As Input By Scanf

Mar 31, 2014

In GCC v4.6, I am encountering a strange problem. If I try to get a character input and a int input like this:

Code:

int main()
{
int a;
char b;
scanf("%d",&a);
scanf("%c",&b);
}

the compiled program asks for input only one time. On the other hand, if I do the char scanf earlier like this:

Code:

int main()
{
int a;
char b;
scanf("%c",&b);
scanf("%d",&a);
}

it asks for input twice.

View 6 Replies View Related

C :: Trying To Scanf A Char And Code Just Jump Over It

Jan 25, 2014

I'm doing a code to calculate the final grade of students. This is a work for college, and I need to keep this structure.

My problem is that last scanf, it is ignored when I compile the code. It "works" if I try to scan a string, float or int.

Code:

#include <stdio.h>
#include <stdlib.h>
void nfinal(float NOTA1,float NOTA2,float NOTA3,char MEDIA){
int NOTA;
if(MEDIA=='A'){
NOTA=(NOTA1+NOTA2+NOTA3)/3;

[Code]....

View 3 Replies View Related

C++ :: Wrong Return Type When Returning Char Array As Pointer

Apr 25, 2014

I am writing a class Player which has several char arrays as private fields. I am trying to write a method which returns an array as a pointer, but doesn't alter the array in any way, thus the const.

Here is a snippet:

Code: class Player
{
private:
char state[MAX_STATE_CHAR + ONE_VALUE];
int rating;
char last[MAX_NAME_CHAR + ONE_VALUE];
char first[MAX_NAME_CHAR + ONE_VALUE];
int groupNumber = NEG_ONE;
public:
char * GetFirst() const
{
return first;
}

Visual studio is saying that the return type doesn't match.

View 3 Replies View Related

C++ :: Variable Assigned Wrong Value?

Nov 15, 2012

Consider the following:

Code:
float foo( float const *bar )
)
{
float temp;
temp = *bar;
...
}

Something I am noticing is that temp right after the assignment to *bar, is not the same value as *bar. This is for a project at work and the code runs on an embedded board with an ARM processor. I've copied the function into a standalone program for both Visual Studio and Code::Blocks and it works correctly there.

View 12 Replies View Related

C :: How To Put Value From Scanf Into Array

May 2, 2013

Code:

#include<stdio.h>
#include<windows.h>
int nr, i, array_new[10],n=0;
main(){
printf ("Insert number: ");
scanf ("%d", &nr);

[Code]...

I need put value from scanf into array. How make this: array_new[nr]?

View 8 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

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?

View 2 Replies View Related

C++ :: Fees Showing Up Wrong On Program

Feb 19, 2014

I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.

Oh yeah the + 10 is for a $10 fee

Code:
else if (checks < 20 || checks >= 0) {
fee = .10 * checks + 10;
cout<< "Bank service charge for the month is $ " << setprecision(4) << endl;
}

View 3 Replies View Related

C :: Guess 4 Int Array With How Many Are In Right And Wrong Positions

Feb 11, 2013

For an assignment I have to create a random array of four integers, and then I have to allow someone to input up to ten guesses to guess the array in the correct order. I also need to be able to display whatever was generated by inputting -1. Finally, after every guess I have to tell the inputter how many of the guessed integers are correct and in the correct position, as well as how many integers are correct but not in the correct position.

So far I've been able to get the random array to generate properly, but inputting negative one has no effect, although if I input it four times in a row I get to my 'lose' condition. Also, it only seems to allow the user to input 4 guesses and not 10 before going straight to the 'lose' condition. I need to get these issues sorted out before I can move on to showing how many guesses are right etc....

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time (NULL));

[Code] ....

View 3 Replies View Related

C# :: Des Encryption Produces Wrong Output

Feb 14, 2012

I have the following function:

Code:
public static void Des(byte[] key, byte[] inBuf, byte[] outBuf) {
if (key.Length != 8 || inBuf.Length != 8 || outBuf.Length != 8) {
throw new Exception("Des: Buffer or key length incorrect.");
}

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

[Code] ....

I do not get the expected output of

Code: { 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 }

instead I get

Code: { 0xC6, 0x61, 0x8D, 0x63, 0x0B, 0x39, 0x31, 0xB0 } am I doing something wrong?

I've even tried reversing the byte order of the test data, and I don't get the right result. I've tested the same data using C++ with CryptoPP on Linux, and I get the expected result, but I'm porting this code to run on .Net, and this is my main stoppage in the process at the moment.

View 5 Replies View Related

C :: Sensor Values Reading Wrong

May 24, 2014

My whole code is working but when the results are sent to my phone only the temperature value is reading correct the light value is all jungled up and moisture and pressure values are reading as 0.

Code:

#include "taskFlyport.h"
#include "grovelib.h"
#include "barometer.h"
#include <string.h>
extern BOOL incomingSMS;
extern int incomingIndexSMS;
extern BYTE incomingMemSMS;

[Code]...

View 4 Replies View Related

C++ :: Sensor Values Reading Wrong

May 26, 2014

I am only receiving the correct temperature value. The other 3 values are reading wrong. My format string isent matching the variable list. What I need to do.

float data_bar = 0.0;
float data = 0.0;
float anVal = 0.0;
float moistureVal = 0.0;
while(1) {

// Get the new value using the get() function

[Code] ....

View 3 Replies View Related

C++ ::  SendInput - Cursor Position Wrong

May 12, 2013

I recently wanted to create a (yet) simple program that simulates a mouse movement.So far I managed to make the program work. It does move the mouse, click when expected but the problem is the location it does click at.Here's my code:

#include <Windows.h>
#include <stdio.h>
int leftclick (DWORD x, DWORD y);
int main(){

[code]......

The problem now is: I want the program (for testing purposes) to click at (1920, 1080) and (100, 100) afterwards. Now it does click within a specific range. When I use GetCursorPos to retreive the cursors position it differs quite a bit from where I expected the click to be.

a second question I have is: When I declare the following flag (in the code above) the program does use relative coordinates even though it shouldn't.

input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;

Where as it works out well when I add a MOUSEEVENTF_MOVE to it.I couldn't find any solution to this in Microsoft MSDN or any other website.

View 2 Replies View Related

C++ :: Check Wrong Input Data

Jan 20, 2013

i'm making a for loop for a mini game which required the user to enter the input number.Let say if the user accidently entered a character instead of integer the whole program will go haywire so is there anyway to check for the error and prompt the user to input the data again?Here is the simple program...

for(row=0;row<4;row++)
{
printf("Enter Row%d:",row);
for(col=0;col<4;col++)
{
scanf("%d",&num[row][col]);
}

View 1 Replies View Related

C++ :: WAV File Reading Wrong Data

Jan 19, 2015

I have been experimenting with a program that loads WAV file and tries to read 1s and 0s from audio file (binary coded information). So far I got working code, but the problem is that I'm not getting correct data. I do get somewhat similar data. The problem is that I get data that amplifies low amplitudes, so instead some noise and binary data I get lots of noise and hard to recognize binary data. My code is this

#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
// An unsigned char can store 1 Bytes (8bits) of data (0-255)

[Code] .....

This is wav file in binary viewer (after header)

0030 0032
00300035003200320035003A0048004A
004C0049004A00510049004300360038

and translated to decimal

48 50
4853505053587274
7673748173675456

and this is output from "wavosaur" program (and this one is correct)

0.001465
0.001526
0.001465
0.001617
0.001526
0.001526
0.001617
0.001770
0.002197
0.002258
0.002319
0.002228
0.002258
0.002472
0.002228
0.002045
0.001648
0.001709

You can see it's not the same. I do get the same data like I do from binary viewer, but I don't understand how they are translated to amplitude value. ? Where is the catch?

So this is not really question about c++, but about wav file structure and reading data.

View 2 Replies View Related

C++ :: Cin Input Validation Returns Wrong

Jul 11, 2014

I have this function that is supposed to take a float as a parameter and then call the getLine() method to accept the users input. The function basically just checks to see if what the user input was of the same data type, if it is it returns the input value, if not then it keeps looping through taking new input until its correct. The problem is no matter what number you put in the output always returns as 140734799803512.

float InputValidation(){
float num;
string strInput;
while (true){
getline(cin, strInput);

[Code] ....

You also need to include <string> and <sstream>.

View 3 Replies View Related

C++ :: Algorithm Producing Wrong Output (Zero)

Jul 14, 2014

Why my calculate function is producing a zero?I feel like it may have something to do with there being zeros the arrays it takes. The arbitrary cout statements are just for my debugging purposes. Input is formatted as follows:

<int>
<int>
<string>,<int>,<int>
<string>,<int>,<int>
<string>,<int>,<int>
<string>,<int>,<int>
and so on

#include <iostream>
#include <string>
#include <sstream>
int** parse_input(int &num_items, int &pouch_size);
int* calculate(int &num_items, int &pouch_size, int *values, int *weights, int &max_value);

[Code] ....

View 1 Replies View Related

C++ :: Asterisk Diamond Is Printing Out Wrong

Sep 6, 2014

I feel as if I'm so close and I'm just messing up a value somewhere, but I am at a loss as to what I should change. Here is my code:

#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {

[Code] ....

View 2 Replies View Related

C++ :: Call By Reference And Returning Wrong Value

Dec 17, 2013

Write your question here.

#include<iostream>
using namespace std;
void getInput(int& numOfDays, double& itemPrice);

[Code].....

So this program is supposed to calculate the price of an item, and return it back as the variable total of type int. but for some reason it gives me a weird output on total. And am i using call by reference correct?

View 1 Replies View Related

C/C++ :: Array Switches Wrong Values

Jun 7, 2014

I have a game that requires the switching of tiles. When I try to switch the blank tile (_) with 5, the 5 switches with the 8 instead of the tile switching with the blank tile. The code behaves the same with top row. I have observed that this only happen in the row and column bound by [0][0]; For example the four top left tiles ([8, 7, 5, are 4]) are behave erratically.

Here is sample code!

//swap if columns are equal and blank is to bottom
else if ((blankCol==tileCol) && (blankRow-tileRow==1)) {
temp = board[blankRow][blankCol];
board[blankRow][blankCol] = board[tileRow][tileCol];
board[tileRow][tileCol] = temp;
return true;
}

I am thinking perhaps there may be a double switch but then again why does it for only the left column and top row.

Attached image(s)

View 2 Replies View Related

C# :: Delegate Wrong Return Type?

Feb 25, 2014

i'm getting a new error is a wrong return type.

WebAPI.cs
namespace DarkAPP___WForm.Libs {
class WebAPI {
System.Net.WebClient wc = new System.Net.WebClient();
public WebAPI() {

[code].....

View 6 Replies View Related

C :: Get Rid Of Space / Use Scanf Or Getchar

Sep 24, 2014

I want the user to be able to enter a command then a character, like for example: push r....I want the command to be stored in the array command, and the character to be stored in the variable c.

Now I wonder what the best way to get rid of the space is, using scanf or getchar (see below for code, only thing that I changed between the 2 versions is the statement before the comment "get rid of space")? Or maybe it doesnt matter?

Code:

include <stdio.h>
#define MAX 200
void push(char c); // Puts a new element last in queue
char pop(void); // Gets the first element in queue
static char s[MAX];
}

[code]....

View 6 Replies View Related

C :: How To Write Scanf With Right Parameters

Jun 30, 2013

How can i upgrade my program I want to input a octal and binary number and convert them in base 2, 8, 10, 16..

how can I write the scanf with the right parameter in it??

Code:
scanf ("%x",&i); Code: #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main() {
int i;
char buffer [33];

[Code] .....

View 5 Replies View Related

C :: Scanf / Fgets Without Echo

Aug 31, 2014

I am trying to write a terminal-like chat application in Linux. I would like to use a FIFO queue to print out the messages in terminal. The queue would be populated from 2 sources- stdin and messages sent from the other user over TCP. I have meet an obstacle that I cannot handle...

Lets say I would like to take user input using fgets and put it into a buffer. Then queue it if the buffer is not empty or print if it is. The problem is that when I use fgets or scanf, my input is instantly printed to the terminal..If i do:

Code:

fgets(message, 100, stdin); printf

("%s", message The string under message is printed twice :|. Is there a way to prevent this?

View 5 Replies View Related

C :: Scanf With Stopping Condition

Mar 22, 2013

I wanted to input some numbers with scanf function, i can enter some numbers and if I input -1 to the scanf, the input must end. And the scanf function has limited input, the max that I can input is 40 numbers.example if enter 1 2 4 6 5 4 -1 the scanf function will ended and the result will be appear.I wanted to know how the scanf function is like that would be best for this problem, Code: scanf("%d", &n); the result if I input those number will be like

|
||
||||
||||||
|||||
||||

View 3 Replies View Related







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