Seite 1 von 1

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 7:57 pm
von Payne
<BLOCKQUOTE><font size="1" face="Verdana, Arial">Code:</font><HR><pre>/***************************************************************************
main.c - description
-------------------
begin : Sam Sep 1 15:21:16 CEST 2001
copyright : (C) 2001 by Payne
email : [email protected]
homepage : [url=http://www.retrogaming.de,]www.retrogaming.de,[/url] www.paynesserver.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/***************************************************************************

Vielleicht entdeckt ihr eine Formel, wenn ihr das programm mehrmals benutzt.
Mir ist sie auch nicht aufgefallen, und ich dachte erst, es wäre ein Bug :D ...
Man könnte das Ganze also _VIEL_ einfach coden, aber das hier ist mein erstes
nützliches C-Programm, mit Ein- und Ausgabe, Variablen und IF-Anweisungen.

Ach und lacht nicht über den Hinweis auf die GPL, KDevelop hat das
automatisch hingeschrieben :-)

***************************************************************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

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


int main(int argc, char *argv[])


{
float x;
float wert1=5,wert2=10,wert3=25;
float verlust;
char waehrung[80]=" DM"; // Leerzeichen vor der Währung beachten....


printf("Wieviel Taschengeld bekommst du in ");
printf("%s",&waehrung);
printf("/Monat ?

");
scanf("%f",&x);
printf("
Du bekommst also ");
printf("%.2f",x);
printf("%s",&waehrung);
printf(" Tachengeld pro Monat.
Ich werde jetzt berechnen,
");
printf("wieviel ");
printf("%s",&waehrung);
printf(" du im Jahr Verlust machst,
weil du dein Tachengeld nicht wöchentlich verlangst:

");

printf("%.2f",x * 12);
printf("%s",&waehrung);
printf(" bekommst du im Jahr,
wenn du dein Taschengeld pro Monat bekommst.

");

/*
printf("%f",x / 4);
printf("%s",&waehrung);
printf(" würdest du pro Woche bekommen.

");
*/

printf("%.2f",x / 4 * 52);
printf("%s",&waehrung);
printf(" würdest du im Jahr bekommen,
wenn du dein Geld wöchentlich verlangen würdest !

");

printf("Bist du dir überhaupt darüber klar,
dass du im Jahr ");

verlust= x / 4 * 52 - x * 12;

printf("%.2f",verlust);
printf("%s",&waehrung);
printf(" im Jahr Verlust machst !?

");


if (verlust <= wert1)
{
printf("Von den ");
printf("%f ",verlust);
printf("%s",&waehrung);
printf(" könntest du dir ein paar Cola-Dosen kaufen :D");
}

if (verlust > wert1 && verlust <= wert2)
{
printf("Von den ");
printf("%.2f ",verlust);
printf("%s",&waehrung);
printf(" könntest du dir vielleicht ein Pack CD-Rohlinge kaufen, für deine Romsammlung *g*");
}


if (verlust > wert2 && verlust < wert3)
{
printf("Von den ");
printf("%.2f ",verlust);
printf("%s",&waehrung);
printf(" könntest du dir eventuell ein Spiel vom Freund abkaufen :-)");
}


if (verlust >= wert3)
{
printf("Von den ");
printf("%.2f ",verlust);
printf("%s",&waehrung);
printf(" könntest du dir mindestens ein altes Computerspiel leisten !");
}

return EXIT_SUCCESS;
}

</pre><HR></BLOCKQUOTE>

[ 03. September 2001: Beitrag editiert von: Payne ]

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 8:22 pm
von Imoto
Konichi wa! Liest sich nicht schlecht.

<BLOCKQUOTE><font size="1" face="Verdana, Arial">Code:</font><HR><pre>
#include <string.h>
#include <stdio.h>
#include <windows.h>
#include <windowsx.h>

//LPSTR g_lpCmdLine;

#define GWL_TEXT 0
#define GWL_XY 4

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{

switch (uMsg)
{
case WM_CLOSE:
::PostQuitMessage(0);
::DestroyWindow(hwnd);
break;

case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hDC = ::BeginPaint(hwnd, &ps);
RECT rect;
::GetClientRect(hwnd, &rect);
char* pText = (char*) ::GetWindowLong(hwnd, GWL_TEXT);
LPARAM lXY = (LPARAM) ::GetWindowLong(hwnd, GWL_XY);
char str[40];
sprintf(str, "x = %d, y = %d", GET_X_LPARAM(lXY), GET_Y_LPARAM(lXY));
::DrawText(hDC, pText, -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
::DrawText(hDC, str, -1, &rect, DT_LEFT);
::EndPaint(hwnd, &ps);
}
break;

case WM_SETTEXT:
{
::SetWindowLong(hwnd, GWL_TEXT, (LONG) lParam);
}
break;

case WM_LBUTTONDOWN:
{
::SetWindowLong(hwnd, GWL_XY, (LONG) lParam);
::InvalidateRect(hwnd, NULL, TRUE);
}
break;

default:
return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
//g_lpCmdLine = lpCmdLine;

// Register my window class
WNDCLASSEX wndcls;
wndcls.cbSize = sizeof wndcls;
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = WindowProc;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 8;
wndcls.hInstance = hInstance;
wndcls.hIcon = NULL;
wndcls.hCursor = (HCURSOR) ::LoadCursor(NULL, IDC_ARROW);
//wndcls.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wndcls.hbrBackground = ::CreateSolidBrush(0x00314939);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = "Windowklasse";
wndcls.hIconSm = NULL;
::RegisterClassEx(&wndcls);

// Create my main window
HWND hwnd = ::CreateWindow(
"Windowklasse", // name of window class
"Hello World", // title-bar string
WS_OVERLAPPEDWINDOW, // top-level window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
(HWND) NULL, // no owner window
(HMENU) NULL, // use class menu
hInstance, // handle to application instance
(LPVOID) NULL); // no window-creation data

::UpdateWindow(hwnd);

::ShowWindow(hwnd, nCmdShow);

::SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) lpCmdLine);

MSG msg;
while (::GetMessage(&msg, NULL, 0, 0))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}

return 0;
}

</pre><HR></BLOCKQUOTE>

Dieses C-Programm ist relativ Billig, es erscheint nur ein Fenster, und kannst da Klicken und so.

Ölk-chan

PlayStation: Ich habe irgend wo noch eine neuere Version rumliegen, da wird sogar die Grösse und Position des Fensters angezeigt.

[Doppelpunktfehler wegen Smilies entfernt]

[ 03. September 2001: Beitrag editiert von: Ölk-hglhgl ]

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 8:41 pm
von Payne
Mein Programm läuft inner Konsole. Ich habe es unter Linux mit KDevelop gecodet, aber das is so billiges C, das sollte portierbar sein

@Ölk
Ich versuch gerade mal dein Code zu portieren, es kommen noch 2 Fehler...

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 8:45 pm
von Imoto
Konichi wa!

Öh.. und welche zwei??? Bei mir Funzt es. Aber es ist möglich das er probleme mit den Dopeelpunkten (:) hat.

Ölk-chan

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 9:55 pm
von Payne
Nein, unter Linux habe ich keine windows(x).h Bild

Mein erstes sinnvolles C-Programm !!

Verfasst: Mo Sep 03, 2001 9:58 pm
von Imoto
Konichi wa!

Jup, (Hab per Zufall gerade den Win XP Thread gelesen Bild)

Gibbet da auch eine Alternative zu?

Ölk-chan

PlayStation: Mein Vorgesetzter (Big Boss einer erfolgreichen Entwicklungsfirma) hat mir gesagt, das Windows das momentan mächtigste Betriebssystem auf dem irdischen Markt ist.