Jump to content

Need Help With Basic C Program !

VexKrad

Hey Wassup Everyone So I'll Start With Basic , I Barely Know how to code ,  i mean i kinda know how to code but most of the time i end up wrong, tho im practising and improving my skills everyday ..so our tutor gave us this project a simple program to code ' a calculator , relax i don't want anyone to make it for me , i have made one with my best efforts ,( note that our tutor have taught us limed aspects of c like he still havn't taught use arrays and stuff , and for time being he wants us to code a calculator that can take three integers at a time and perform operations like addition and multiplication at the same time and wants the user to decide if he wants to perform simple calculations or complex like just additon 2 integers , k so getting on the help stuff now i coded a calculator with my best efforts and im still a learner my program runs ikd half like it can perform simple with eazy but when it comes to three integer additon or multiplictions it does not give give nay output idk why ! i have attached my code in pastebin link and i want someone to check where im going wrong and possible correct me ! please help me !! Thank You 

 

 link https://pastebin.com/gg5GsL61

 

If Your Too Lazy To Go to link 

 

_______________________________________

 

  1. #include <stdio.h>
  2. int main()
  3. {
  4.     ProgramRestart : printf("\n _________________________________________________ \n");
  5.     int a,b,c,d,e,f,o;                   //Declaring Values//
  6.  
  7.  {
  8. printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
  9. scanf("%d",&a);
  10. printf("Enter Value Of B: \n");
  11. scanf("%d",&b);
  12. printf("Enter Value Of ? \n");
  13. scanf("%d",&c);
  14.    
  15.    }
  16.  
  17. {
  18.     printf("Enter Operator: ");      //Declaring Operator //
  19.     scanf("%s",&o);
  20. }
  21.  
  22. { switch(o)
  23. { case '+' :                 //If User Selects Addition As Operator //
  24.    d=a+b;
  25. printf("\n The Sum Of A&B = %d",d);
  26. break;
  27.  
  28. case '-' :                   //If User Select Subtraction As Operator //
  29. d= a-b;
  30. printf("\n The Subtraction Of A&B = %d",d);
  31. break;
  32.  
  33. case '*' :                    //If User Select Multiplication As Operator //
  34. d= a*b;
  35. printf("\nThe Multiplication Of A&B =  %d",d);
  36. break;
  37.  
  38. case '/' :                    //If User Select Divison As Operator //
  39. d= a/b;
  40. printf("\n The Division Of A&B = %d",d);
  41. break;
  42.  
  43. case '++' :                   //If The User Desire Addition Of Three Intergers//
  44. f=a+b+c;
  45. printf("\n The Result Of (A+B)+C = %d ",f);      
  46. break;
  47.  
  48. case '+-' :                   //If The User Desire Additon & Subtraction of Three Integers //
  49. f=a+b-c;
  50. printf("\n The Result Of (A+B)-C = %d",f);
  51. break;
  52.  
  53. case '+*' :               //If User Desires Additon & Multiplication Of Three Integers //
  54. f=(a+b)*c;
  55. printf("\n The Result Of (A+B)*C = %d",f);
  56. break;
  57.  
  58. case '+/' :              //If User Desires Addition & Division Of Three Integers //
  59.  
  60. f=(a+b)/c;
  61. printf("\n The Result Of (A+B)/C = %d",f);
  62. break;
  63.  
  64.  
  65.  }
  66.  
  67.   goto ProgramRestart;
  68.    }
  69.  
  70. }
 
___________________________________-
Link to comment
Share on other sites

Link to post
Share on other sites

Check your  {  ... looks like you've put the printf instructions outside the main function.

 

Using goto is really frowned upon in C, avoid it.

 

Use while (1==1)  { }  or some equivalent.

 

Also, are you use "o" variable is an int?  are you reading a number or a character ?

Link to comment
Share on other sites

Link to post
Share on other sites

19 minutes ago, mariushm said:

Check your  {  ... looks like you've put the printf instructions outside the main function.

 

Using goto is really frowned upon in C, avoid it.

 

Use while (1==1)  { }  or some equivalent.

 

Also, are you use "o" variable is an int?  are you reading a number or a character ?

k so imma breif what im facing like i checked  what u said even tho im unsure of what really it means ,, you want me to use a loop ,, and yes i added o in int like im unsure its like i want my user to input a charcter that is checked and correct case it used and im kinda unsure how to use it , i managed to make it work a bit so what s ur  suggestion what should ,, like im unsure of some concepts ,, and goto i used for making the program run again and again like a user don't have to run in again & again.. 

Link to comment
Share on other sites

Link to post
Share on other sites

    int a,b,c,d,e,f,o;  

    scanf("%s",&o);

 

as @mariushm pointed out, youre reading string into an integer,

i think what happens is it actually reads first symbol and converts it to number but you dont have a switch-case with corresponding number so it just does nothing?

MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to comment
Share on other sites

Link to post
Share on other sites

9 minutes ago, Neftex said:

    int a,b,c,d,e,f,o;  

    scanf("%s",&o);

 

as @mariushm pointed out, youre reading string into an integer,

i think what happens is it actually reads first symbol and converts it to number but you dont have a switch-case with any number so it just does nothing?

im a noobie like i coded this after one day in class where our tutor taught us basics and im really unsure what each and everhting means and using %s im unsure what i did there coz i might have taken it from internet and tried and it might have worked so lets break it down i want my user to input charcters like " ++ , - - " etc so im make a case from them and want it to perform the code i introduced inside it so can you actally suggest me like what im doing like or idk actually tell me what and where i need to change in order for this to work !

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, VexKrad said:

im a noobie like i coded this after one day in class where our tutor taught us basics and im really unsure what each and everhting means and using %s im unsure what i did there coz i might have taken it from internet and tried and it might have worked so lets break it down i want my user to input charcters like " ++ , - - " etc so im make a case from them and want it to perform the code i introduced inside it so can you actally suggest me like what im doing like or idk actually tell me what and where i need to change in order for this to work !

i havent touched C for quite a while but i think these steps could fix it:

1) remove "o" from "int a,b,c,d,e,f,o;"

2) add line "char o[2];"

3) remove & from " scanf("%s",o);"

 

edit: changed code, might work now?

MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to comment
Share on other sites

Link to post
Share on other sites

#include <stdio.h>
int main()
{
    ProgramRestart : printf("\n _________________________________________________ \n");
    int a,b,c,d,e,f,o;                   //Declaring Values//
 
 {
printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
scanf("%d",&a);
printf("Enter Value Of B: \n");
scanf("%d",&b);
printf("Enter Value Of C: \n");
scanf("%d",&c);
   
   }
 
{
    printf("Enter Operator: ");      //Declaring Operator //
    scanf("%s",&o);
}
 
{ switch(o)
{ case '+' :                 //If User Selects Addition As Operator //
   d=a+b;
printf("\n The Sum Of A&B = %d",d);
break;
 
case '-' :                   //If User Select Subtraction As Operator //
d= a-b;
printf("\n The Subtraction Of A&B = %d",d);
break;
 
case '*' :                    //If User Select Multiplication As Operator //
d= a*b;
printf("\nThe Multiplication Of A&B =  %d",d);
break;
 
case '/' :                    //If User Select Divison As Operator //
d= a/b;
printf("\n The Division Of A&B = %d",d);
break;
 
case '++' :                   //If The User Desire Addition Of Three Intergers//
f=a+b+c;
printf("\n The Result Of (A+B)+C = %d ",f);      
break;
 
case '+-' :                   //If The User Desire Additon & Subtraction of Three Integers //
f=a+b-c;
printf("\n The Result Of (A+B)-C = %d",f);
break;
 
case '+*' :               //If User Desires Additon & Multiplication Of Three Integers //
f=(a+b)*c;
printf("\n The Result Of (A+B)*C = %d",f);
break;
 
case '+/' :              //If User Desires Addition & Division Of Three Integers //
 
f=(a+b)/c;
printf("\n The Result Of (A+B)/C = %d",f);
break;
 
 
 }
 
  goto ProgramRestart;
   }
 
}

Holy terrible practices.

Here are the first steps to debugging this:

  1. Remove all unnecessary curly braces. This program, as it is currently written only requires 2 pairs (2 open, and 2 close) of curly braces.
    1. This is extremely important. Everything declared inside a set of curly braces is only "in scope" until the closing brace for the block it was declared in.
  2. Fix your indentation. Everything inside curly braces should be indented by one tab further than the statement which the curly braces belong to: for example:
    1. int main()
      {
        int a, b, c, d, e;
        
        switch (a)
        {
          case 0:
            int seeTheIndentation;
            break;
        }
        
        return 0;
      }

       

    2. This is important because it makes it so much easier to read the program and see what's going on.
       

  3. Come back, and post the reformatted code in code tags.

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Neftex said:

i havent touched C for quite a while but i think these steps could fix it:

1) remove "o" from "int a,b,c,d,e,f,o;"

2) add line "char* o;"

l i tried but now the switch lines gives mt error like says o is not a integer but imma keep trying and let u know any possible resaosn or mistake i might be making

Link to comment
Share on other sites

Link to post
Share on other sites

@VexKrad i changed the code above, try again (if it still doesnt work, youll have to wait for someone else :) )

MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, straight_stewie said:

#include <stdio.h>
int main()
{
    ProgramRestart : printf("\n _________________________________________________ \n");
    int a,b,c,d,e,f,o;                   //Declaring Values//
 
 {
printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
scanf("%d",&a);
printf("Enter Value Of B: \n");
scanf("%d",&b);
printf("Enter Value Of C: \n");
scanf("%d",&c);
   
   }
 
{
    printf("Enter Operator: ");      //Declaring Operator //
    scanf("%s",&o);
}
 
{ switch(o)
{ case '+' :                 //If User Selects Addition As Operator //
   d=a+b;
printf("\n The Sum Of A&B = %d",d);
break;
 
case '-' :                   //If User Select Subtraction As Operator //
d= a-b;
printf("\n The Subtraction Of A&B = %d",d);
break;
 
case '*' :                    //If User Select Multiplication As Operator //
d= a*b;
printf("\nThe Multiplication Of A&B =  %d",d);
break;
 
case '/' :                    //If User Select Divison As Operator //
d= a/b;
printf("\n The Division Of A&B = %d",d);
break;
 
case '++' :                   //If The User Desire Addition Of Three Intergers//
f=a+b+c;
printf("\n The Result Of (A+B)+C = %d ",f);      
break;
 
case '+-' :                   //If The User Desire Additon & Subtraction of Three Integers //
f=a+b-c;
printf("\n The Result Of (A+B)-C = %d",f);
break;
 
case '+*' :               //If User Desires Additon & Multiplication Of Three Integers //
f=(a+b)*c;
printf("\n The Result Of (A+B)*C = %d",f);
break;
 
case '+/' :              //If User Desires Addition & Division Of Three Integers //
 
f=(a+b)/c;
printf("\n The Result Of (A+B)/C = %d",f);
break;
 
 
 }
 
  goto ProgramRestart;
   }
 
}

Holy terrible practices.

Here are the first steps to debugging this:

  1. Remove all unnecessary curly braces. This program, as it is currently written only requires 2 pairs (2 open, and 2 close) of curly braces.
  2. Fix your indentation. Everything inside curly braces should be indented by one tab further than the statement which the curly braces belong to: for example:
    1. 
      int main()
      {
        int a, b, c, d, e;
        
        switch (a)
        {
          case 0:
            int seeTheIndentation;
            break;
        }
        
        return 0;
      }


       

 

k i get what u saying sir , i was like making blocks for a clear representation but ended up making more mess lol, second yeh i get what u said  is it basciay for clear visula represttion or it is actully making a error in my code uggh sksks i still getting error lol 

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, VexKrad said:

l i tried but now the switch lines gives mt error like says o is not a integer but imma keep trying and let u know any possible resaosn or mistake i might be making

The reason why you're getting those kind of errors is because of all the erroneous curly braces.

For example:

{
  int a = 22;
}

switch (a)
{
  case 0:
    break;
    
  // the rest of the cases.
}

Will produce an error because "a" does not exist at the switch statement.

Variables in C are subject to something called "scope". Scope is just a way of describing the availability of a variable to your program. A "thing" is only "in scope" when it is inside the curly braces it was declared in. It is not accessible outside of that block. Or, in other words: variables go "out of scope" and become unavailable once you reach the closing curly brace of a block of code.

The way to format and organize your code to keep it easily readable, which is what you've said you are using curly braces for, is to use whitespace: tabs, newlines, and spaces.

 

For example:

int main()
{
int a=0;
int b=1;  
int c=a+b;
return 0;
}

is valid, but this:

int main()
{
  int a = 0;
  int b = 1;
  
  int c = a + b;
  
  return 0;
}

is much more readable.

 

If you need a marker to more rigorously separate a block of code from something else, use a comment:

int main()
{
  // declare variables
  int a;
  int b;
  int c, d;
  
  /* Do random things to assign
   * values to variables.
   */
  a = scanf("%d", a);
  b = 3;
  c = a + b;
  d = c * 1337;
  
  // print the result
  printf("%d", d);
}

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

@VexKrad one last try :D

 

1) remove "o" from "int a,b,c,d,e,f,o;"

2) add line "char o[2];"

3) remove "&" from " scanf("%s",&o);"

 

MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to comment
Share on other sites

Link to post
Share on other sites

#include <stdio.h>
int main()
{
	ProgramRestart : printf("\n _________________________________________________ \n");
	int a,b,c,d,e,f ;
	char o;                   //Declaring Values//
    
 
printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
scanf("%d",&a);
printf("Enter Value Of B: \n");
scanf("%d",&b);
printf("Enter Value Of C: \n");
scanf("%d",&c);
   
   


	printf("Enter Operator: ");      //Declaring Operator //
	scanf("%s",&o);


 switch(o)
{

case '+' :                 //If User Selects Addition As Operator //
   d=a+b;
printf("\n The Sum Of A&B = %d",d);
break;

case '-' :                   //If User Select Subtraction As Operator //
d= a-b;
printf("\n The Subtraction Of A&B = %d",d);
break;

case '*' :                    //If User Select Multiplication As Operator //
d= a*b;
printf("\nThe Multiplication Of A&B =  %d",d);
break;

case '/' :                    //If User Select Divison As Operator //
d= a/b;
printf("\n The Division Of A&B = %d",d);
break;

case '++' :                   //If The User Desire Addition Of Three Intergers//
f=a+b+c;
printf("\n The Result Of (A+B)+C = %d ",f);      
break;

case '+-' :                   //If The User Desire Additon & Subtraction of Three Integers //
f=a+b-c;
printf("\n The Result Of (A+B)-C = %d",f);
break;

case '+*' :               //If User Desires Additon & Multiplication Of Three Integers //
f=(a+b)*c;
printf("\n The Result Of (A+B)*C = %d",f);
break;

case '+/' :              //If User Desires Addition & Division Of Three Integers // 

f=(a+b)/c;
printf("\n The Result Of (A+B)/C = %d",f);
break;

}
  
  goto ProgramRestart;
   }


This Is What Did With My Code Ik still a mess but ugh same problem like it works for '++' perfectly but when i try other like '+-' i get no output 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Neftex said:

@VexKrad one last try :D

 

1) remove "o" from "int a,b,c,d,e,f,o;"

2) add line "char o[2];"

3) remove "&" from " scanf("%s",&o);"

 

Error : Switch Quantity is not a integer

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, VexKrad said:

This Is What Did With My Code Ik still a mess but ugh same problem like it works for '++' perfectly but when i try other like '+-' i get no output 

Do this test: Enter three numbers, then for the operation, type exactly as follows:

  1. +
  2. -
  3. "hit the enter key"

Then post what your inputs were, in the order you gave them to the program, and what the output was.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, VexKrad said:

Error : Switch Quantity is not a integer 

well, i just read you cant use switch for strings, so i guess if you want it to work on multiple characters, youll have to use if()

MSI GX660 + i7 920XM @ 2.8GHz + GTX 970M + Samsung SSD 830 256GB

Link to comment
Share on other sites

Link to post
Share on other sites

12 hours ago, straight_stewie said:

Do this test: Enter three numbers, then for the operation, type exactly as follows:

  1. +
  2. -
  3. "hit the enter key"

Then post what your inputs were, in the order you gave them to the program, and what the output was.

it works for two integers perfectly fine but like when i input two character in the enter operator field it dosn't work ugggh imma relaz and try to understand the logic and fine a understand a alternative way

Link to comment
Share on other sites

Link to post
Share on other sites

@VexKrad

 

You define 'o' as a single character variable. How are you planning on storing multiple characters in that single space? And even if you were to only read in a single character it would still cause undefined behavior because you ask for a string (%s) and strings are 0-terminated. You need a single character worth of space for storing that terminating zero alone so you overrun your "buffer".

 

Note that scanf is nasty for even allowing this, which is why you should not be using it. I'd also make it a habit to check the result of operations. Every call to scanf can fail. (for example, because you enter text when it expects a number). After such a failed call the data that stay stuck in the input buffer causes your program to "act weird" on subsequent calls to scanf. Says a lot about modern schooling that they still teach it this poorly.

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, VexKrad said:

it works for two integers perfectly fine but like when i input two character in the enter operator field it dosn't work ugggh imma relaz and try to understand the logic and fine a understand a alternative way 

Think about what a "char" is.

A char is a single byte. It can hold either a single ASCII character or some 8 bit integer type from -127 to +127.

In C, there is no such thing as a "string". There is only "char[]" which is an array of chars. You said that you haven't learned about arrays yet, so you've got a decision to make:

  1. You can continue using a char, but change your choices to be all only a single character.
  2. You can teach yourself about arrays. They really aren't that hard.
    1. // It is very important that this is 3 
      // chars long, even though we are only accepting 
      // input of two chars at a time.
      // scanf will append an "End of String"
      // charater: /0, to the end of strings that it reads.
      char choice[3];
      
      scanf("%2s", choice);
      
      switch (choice[0])
      {
        case '+':
          switch (choice[1])
          {
            case '-':
              break;
              
              // additional second character cases
          }
          
          // additional first character cases
      }

       

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, straight_stewie said:

Think about what a "char" is.

A char is a single byte. It can hold either a single ASCII character or some 8 bit integer type from -127 to +127.

In C, there is no such thing as a "string". There is only "char[]" which is an array of chars. You said that you haven't learned about arrays yet, so you've got a decision to make:

  1. You can continue using a char, but change your choices to be all only a single character.
  2. You can teach yourself about arrays. They really aren't that hard.
    1. 
      // It is very important that this is 3 
      // chars long, even though we are only accepting 
      // input of two chars at a time.
      // scanf will append an "End of String"
      // charater: /0, to the end of strings that it reads.
      char choice[3];
      
      scanf("%2s", choice);
      
      switch (choice[0])
      {
        case '+':
          switch (choice[1])
          {
            case '-':
              break;
              
              // additional second character cases
          }
          
          // additional first character cases
      }

       

Im Open Mind , Even Tho Our Tutor Didi not tauht im gonna go with the seconf option and actually learn about arrays , untill i'll use the one with two calculator . thank you guyz for helping me 

Link to comment
Share on other sites

Link to post
Share on other sites

This Is What I am Gonna Submit .

#include <stdio.h>
int main()
{
	ProgramRestart : printf("\n _________________________________________________ \n");
	int a,b,c,d;                   //Declaring Values//

 {
printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
scanf("%d",&a);
printf("Enter Value Of B: \n");
scanf("%d",&b);
   
   }

{
	printf("Enter Operator: ");      //Declaring Operator //
	scanf("%s",&c);
}

{ switch(c) 
{ case '+' :                 //If User Selects Addition As Operator //
   d=a+b;
printf("\n The Sum Of A&B = %d",d);
break;

case '-' :                   //If User Select Subtraction As Operator //
d= a-b;
printf("\n The Subtraction Of A&B = %d",d);
break;

case '*' :                    //If User Select Multiplication As Operator //
d= a*b;
printf("\nThe Multiplication Of A&B =  %d",d);
break;

case '/' :                    //If User Select Divison As Operator //
d= a/b;
printf("\n The Division Of A&B = %d",d);
break;
 }
  
  goto ProgramRestart;
   }

}

 

Link to comment
Share on other sites

Link to post
Share on other sites

Get rid of that goto

for example, add an int variable called finish and initialize it with 0;

 

do everything that needs to be done lots of time in a while (finish == 0) { all your stuff here }

ask for the operation first with a nice message and add an operator for exiting, for example

Operation  ( + , - , * , /  or q to quit) :

read operation

if ((operation != 'q') && (operation!='Q')) {

 read first number

 read second number

}

Switch operation 

[ all your cases ]

  case 'q':

 case 'Q': 

   finish = 1;

   break;

end switch

 

 

In the division section, add a check to see if b is equal to 0 or not. If it's 0, print an error message and don't perform the division (the program may/will crash with a division by zero otherwise)

 

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure whether I should post this or not, but just to show an example of what a "good beginners solution" to this problem might look like, I will post an incomplete version of a reasonable solution, and leave it to you to figure out how to expand it to solve your problem. That way, if you decide to submit my code instead of yours, you will fail. But, it shows a couple of methods that are useful for this kind of thing.

It is in a spoiler. Please use this as an example of what a solution should look like, and not as me doing your work for you. In order to demonstrate the things I want to demonstrate, the code I'm posting has to be more complete than I would otherwise like it to be. However, as it stands, this will only handle two numbers and a single operation.

Spoiler

#include <stdio.h>

int CalculatorOperations(char choice, int a, int b)
{
  switch (choice)
  {
    case '+':
      return a + b;
      
    default: // the user didn't enter a valid choice
      return 0;
  }
}
  
int main()
{
  int a = 0;
  int b = 0;
  
  printf("Please enter the value of A:\n");
  scanf("%d", &a);
  
  printf("Please enter the value of B:\n");
  scanf("%d", &b);
  
  int numOperations = 0;
  char operation;
  
  while (numOperations < 1)
  {
    printf("Please enter the %d operation:\n", numOperations + 1);
    scanf(" %c", &operation);
      
    if (!numOperations) // do first operator stuff
        a = CalculatorOperations(operation, a, b);
        
    else  // do second operator stuff
      ;
        
    numOperations += 1;
  }
  
  printf("The result is %d\n", a);
  
  return 0;
}

 

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, VexKrad said:

This Is What I am Gonna Submit .


#include <stdio.h>
int main()
{
	ProgramRestart : printf("\n _________________________________________________ \n");
	int a,b,c,d;                   //Declaring Values//

 {
printf("\nEnter Value Of A: \n");       // Inputing Value of Intergers //
scanf("%d",&a);
printf("Enter Value Of B: \n");
scanf("%d",&b);
   
   }

{
	printf("Enter Operator: ");      //Declaring Operator //
	scanf("%s",&c);
}

{ switch(c) 
{ case '+' :                 //If User Selects Addition As Operator //
   d=a+b;
printf("\n The Sum Of A&B = %d",d);
break;

case '-' :                   //If User Select Subtraction As Operator //
d= a-b;
printf("\n The Subtraction Of A&B = %d",d);
break;

case '*' :                    //If User Select Multiplication As Operator //
d= a*b;
printf("\nThe Multiplication Of A&B =  %d",d);
break;

case '/' :                    //If User Select Divison As Operator //
d= a/b;
printf("\n The Division Of A&B = %d",d);
break;
 }
  
  goto ProgramRestart;
   }

}

 

It's broken, you're scanning a string into a int.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×