473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

i need a code for solving operations..

this is my project
i need a code that will show like this..
"first number __"
"second number ___"
"choose operation:
addition..subtraction..multiplication..division"
"the answer is ___"

the user will input his number,
then he will choose also what operation to use..

this is the code that i made:

#include<stdio.h>
#include<conio.h>
main()
{

int num1;
int num2;
int ans;
char oper;

printf("the first number is \n");
scanf("%d",&num1);
printf("the second number is \n);
scanf("%d",num2);
printf(choose operation: \naddition = a\n subtraction = b\n multiplication = c\n division = d\n);
scanf("%c",oper);

for (oper = a;oper = num1+num2;oper ==ans);
printf("the naswer is %d",ans);

getch();
}

im really confuse on doing this..

please help me..
Jul 27 '07 #1
3 1569
JosAH
11,448 Expert 8TB
this is my project
i need a code that will show like this..
"first number __"
"second number ___"
"choose operation:
addition..subtraction..multiplication..division"
"the answer is ___"

the user will input his number,
then he will choose also what operation to use..

this is the code that i made:

#include<stdio.h>
#include<conio.h>
main()
{

int num1;
int num2;
int ans;
char oper;

printf("the first number is \n");
scanf("%d",&num1);
printf("the second number is \n);
scanf("%d",num2);
printf(choose operation: \naddition = a\n subtraction = b\n multiplication = c\n division = d\n);
scanf("%c",oper);

for (oper = a;oper = num1+num2;oper ==ans);
printf("the naswer is %d",ans);

getch();
}

im really confuse on doing this..

please help me..
The reading part is sort of ok (it doesn't work yet though) but it's the second
part of your code that surprises me:

Expand|Select|Wrap|Line Numbers
  1. for (oper = a;oper = num1+num2;oper ==ans);
  2. printf("the naswer is %d",ans);
  3.  
What did you have in mind when you wrote that? You have two numbers: num1
and num2; you have a character oper and according to its value you should do
something. I had a series of if - else statement in mind or a switch statement
but not a loop.

kind regards,

Jos
Jul 27 '07 #2
Meetee
931 Expert Mod 512MB
this is my project
i need a code that will show like this..
"first number __"
"second number ___"
"choose operation:
addition..subtraction..multiplication..division"
"the answer is ___"

the user will input his number,
then he will choose also what operation to use..

this is the code that i made:

#include<stdio.h>
#include<conio.h>
main()
{

int num1;
int num2;
int ans;
char oper;

printf("the first number is \n");
scanf("%d",&num1);
printf("the second number is \n);
scanf("%d",num2);
printf(choose operation: \naddition = a\n subtraction = b\n multiplication = c\n division = d\n);
scanf("%c",oper);

for (oper = a;oper = num1+num2;oper ==ans);
printf("the naswer is %d",ans);

getch();
}

im really confuse on doing this..

please help me..
You can use case statement in this problem.

like

Expand|Select|Wrap|Line Numbers
  1. switch(string)
  2. {
  3. case addition:
  4. do addition.......
  5.  
  6. case subtraction:
  7. do subtraction...
  8.  
  9. etc:
  10.  
Kindly read tutorial if you want more details about switch case.

Regards
Jul 27 '07 #3
archonmagnus
113 100+
...
printf("the second number is \n);
scanf("%d",num2);
...
Not to be picky, but I think you are missing an ampersand in your second scanf statement.
Jul 27 '07 #4

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

Similar topics

5
by: Mr. X | last post by:
Hello, Let me begin by saying that I am a strong advocate of science, math and engineering students learning to program... just a skill that they need to experience even if they go another path....
13
by: XXXXXX.working.in.my.blood | last post by:
hi all, i need help with linked lists... the problem is this, "reverse the contents of a singly linked list without using a temporary node"... solution with code will be appreciated...
2
by: Thomas Connolly | last post by:
Anyone know if there is a C# equivallent to: enum { LIFFE_SIZE_AUTOMARKETREF = 15 }; typedef char LiffeAutoMarketReference ; Thanks,
1
by: rllioacvuher | last post by:
I need help with a program. I have implemented that following header file with an unordered list using one array, but i need to be able to use an ordered list and 2 arrays (one for the links and one...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
5
by: outofmymind | last post by:
Hi every1, im trying to solve this question, i did some of it but i dont think that its correct or complete: this is the question: Write the definition of a class called Product. A Product...
1
by: klubbhead | last post by:
This part of my program needs to read from 4 parameter files and then displays them on the screen by clicking a different radio button. The program itself works, but my professor says that I have to...
10
by: CuTe_Engineer | last post by:
hii, i have cs assignment i tried to solve it but i still have many errors , plzz help mee :"< it`s not cheating becuz i`ve tried & wrote the prog. i just wanna you to show me my mistakes ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.