473,466 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

All variables set to first input

1 New Member
Why this dont work as it should ?
On Keyboardinput the programm automatically sets all variables on the first input -> I press 7
it sets a == 7
b == 7
entscheidung == 7

:/

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int a,b;
  6.     char entscheidung;
  7.     printf("Hallo, ich bin Ribbley's Programm und zeige dir jetzt, was ich kann!\n");
  8.     printf("Wähle eine Zahl!\n");
  9.     scanf("%i",&a);
  10.     printf("Du hast %i gewählt\n",a);
  11.     printf("Willst du mit %i weiterrechnen?\n",a);
  12.     printf("a) Ja!\n");
  13.     printf("b) Nein!\n");
  14.     scanf("%c",&entscheidung);
  15.     switch (entscheidung)
  16.     {
  17.     case 'b':
  18.         printf("Schade, dann halt nicht.\n");
  19.         break;        
  20.     case 'a':
  21.         printf("Gebe eine zweite Zahl an! Mit dieser wird %i multipliziert!\n",a);
  22.         scanf("%i",&b);
  23.         b = a * b;
  24.         printf("Das Ergebnis lautet %i!\n",b);    
  25.         break;    
  26.     default:
  27.         printf("Du musst 'a' oder 'b' eingeben!\n");
  28.  
  29.     }    
  30.     return 0;    
  31. }
Aug 14 '11 #1

✓ answered by Prosammer

try something like this:

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. bool g_bRunning;
  5.  
  6. int main( int argc, char **argv[], ... )
  7. {
  8.     int a, b;
  9.     g_bRunning = true;
  10.  
  11.     while( g_bRunning ) // while( true )
  12.     {
  13.         // Code...
  14.  
  15.         switch( /*Code*/ )
  16.         {
  17.         case /*Code*/:
  18.                 // ... //
  19.                 break;
  20.         case /*Code*/:
  21.                 // ... //
  22.                 break;
  23.         default:
  24.             /* Print something (output) */
  25.             continue;
  26.         }
  27.  
  28.         break;
  29.     }
  30.  
  31.     // if return getchar() doesn't hold it try:
  32.     return system( "pause" ); /* <------------- */
  33. }
  34.  

1 1152
Prosammer
3 New Member
try something like this:

Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. bool g_bRunning;
  5.  
  6. int main( int argc, char **argv[], ... )
  7. {
  8.     int a, b;
  9.     g_bRunning = true;
  10.  
  11.     while( g_bRunning ) // while( true )
  12.     {
  13.         // Code...
  14.  
  15.         switch( /*Code*/ )
  16.         {
  17.         case /*Code*/:
  18.                 // ... //
  19.                 break;
  20.         case /*Code*/:
  21.                 // ... //
  22.                 break;
  23.         default:
  24.             /* Print something (output) */
  25.             continue;
  26.         }
  27.  
  28.         break;
  29.     }
  30.  
  31.     // if return getchar() doesn't hold it try:
  32.     return system( "pause" ); /* <------------- */
  33. }
  34.  
Aug 14 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: multimatum2 | last post by:
Hello, I need to enable/disable input text forms... But... I need to have the same style (color...) in both modes.. Could you help me ? Thanx a lot A small sample... ...
2
by: UJ | last post by:
I have an aspx page that does some database look ups on the initial load. I then need to do stuff later after an autopostback based on some of the values. So I put some variables in input variables...
1
by: BradenM - Sonoma Computer | last post by:
Hello; I am creating a script that will be taking data from a POST and submitting the data to variables which are placed within a hash for string to data association. Then, using HTML::Table and...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
10
by: strife | last post by:
Hi, This is a homework question. I will try to keep it minimal so not to have anyone do it for me. I am really just stuck on one small spot. I have to figure out the highest number from a users...
1
by: Taras_96 | last post by:
Hi everyone, I've downloaded the PHP code at http://www.inventory-management.org/ and am currently in the process of trying to get the code up and running. I am running PHP version 5.1.6.6, so I...
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
3
by: pwilliams | last post by:
For example: info= input('Enter name address and telephone number\n') I have tried declaring variables in advance ie. var1 = " " var2 = " " var3 = " " but to no avail. Can you please help ?...
0
by: mathilin | last post by:
Hi, I am writing a program to accept multiple user inputs and put these values into a table. This database will end up having hundreds of tables, each table should have the user inputted data. I...
2
by: JaketheSnake27 | last post by:
I'm trying to define a field in a query using an expression. Part of that expression involves using public variables. First of all, is it possible to use variables in a query field? And if it is,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.