PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : C Compiler dreht ab -> 1+2 = xxxxx in c++ gehts?



compufreak
18.05.2010, 07:47
Hallo Community.

Ich habe angefangen mit mal wieder in C reinzulesen.
Dazu folgender Code:



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

int main(int argc, char *argv[])
{
int x,y;
printf("\n\t1 . R E C H E N P R O G R A M M ");
printf("\nBitte x eingeben : ");
scanf("%i",&x);
printf("\nBitte y eingeben : ");
scanf("%y",&y);

printf("\n %i + %i ist %i",x,y,x+y);

system("PAUSE");
return 0;
}

Wenn Ich jetzt in Code::Blocks 2+1 rechne passiert folgendes:
Ich tippe 2+1, er rechnet:
2 + 4199324 = 4199326

in wxDev c++
2 + 2130567168 = 21305671

Komisch ist nur, das wenn Ich das ganze in C++ mache:



#include <iostream>

using namespace std;

int main()
{
int a,b;
cin >> a;
cin >> b;

cout << a + b << endl;
system("pause");
return 0;
}
Bekomme Ich bei 2+1 auch 3 raus.
Wieso gehts in C++, aber nicht in C ?

Es macht mich verrückt.

Über Antworten freue Ich mich.

Gruß

Compufreak

Daran liegt das Problem, toll das mir das jetzt erst auffällt -.-

scanf("%y",&y)

NO COMMENT !

0x30
18.05.2010, 07:53
Mach aus
scanf("%y",&y); mal
scanf("%d",&y); vielleicht klappt es dann auch mit dem Nachbarn :D

// Zu spät :(