I'm suppose to write a program that will ask the user to enter two integers. Then the program will ask the user for one of four letters a to add the numbers, s to subtract the numbers, m to multiply the numbers, or d to divide the two numbers.
If the user enters any character other than the 4 listed, keep asking them over and over until they enter a correct letter. Display on the monitor the two numbers entered the math operation used and the answer of the operation:
What's your aim name? PM it
11 1598
Is there supposed to be any error-checking for the numbers? Or just for the letters?
All you need to do is cin two numbers, then enter a while loop. The while loop will have a condition that a char i == 'a' or i == 's' or i == 'm' or i == 'd'. While you are in that loop, cin i.
Then, you can either use if statements or a switch statement to do the correct operation.
Is there supposed to be any error-checking for the numbers? Or just for the letters?
All you need to do is cin two numbers, then enter a while loop. The while loop will have a condition that a char i == 'a' or i == 's' or i == 'm' or i == 'd'. While you are in that loop, cin i.
Then, you can either use if statements or a switch statement to do the correct operation.
Just the letters
-
== 'a' or i == 's' or i == 'm' or i == 'd'
-
That's all the code ???
-
== 'a' or i == 's' or i == 'm' or i == 'd'
-
That's all the code ???
Absolutely not - I'm not writing the program, you are.
That is the general pseudocode or algorithm to follow. If you break that down and code it, you'll get it. (Though not that little bit there, the whole paragraph was the pseudocode, you just zeroed in on what looked the most like code).
Feel free to post any compiler errors you run into or any sort of declarational statements, but it wouldn't be a learning experience if you didn't have to do a little thinking ;)
hi :im khajeddin.
you should write this program with "switch" structure.and also make a loop that ask the user over and oner again to enter the correct character.here it is what you want:
(then please answer my question which is in the Discussion page of C/C++)
while(1)
{
switch(ch) {
case'a' :
result=number1+numder2;
break;
case's' :
result=number1-number2;
break;
case'm' :
result=number1*number2;
break;
case'd' :
result=number1/number2;
break;
default:
printf("please enter the correct character");
break;
} /*end of while*/
hi :im khajeddin.
you should write this program with "switch" structure.and also make a loop that ask the user over and oner again to enter the correct character.here it is what you want:
(then please answer my question which is in the Discussion page of C/C++)
while(1)
{
switch(ch) {
case'a' :
result=number1+numder2;
break;
case's' :
result=number1-number2;
break;
case'm' :
result=number1*number2;
break;
case'd' :
result=number1/number2;
break;
default:
printf("please enter the correct character");
break;
} /*end of while*/
Man, i always forget about switch statements - good idea.
Man, i always forget about switch statements - good idea.
What should loop look like for the user over and oner again to enter the correct character
Hi,
This may satisfy your need. -
-
int DoOperation(int a_nFirst, int a_nSecond, char &a_cOperation)
-
{
-
int
-
nResult = 0;
-
-
switch(a_cOperation)
-
{
-
case'a' :
-
{
-
nResult = a_nFirst + a_nSecond;
-
break;
-
}
-
-
case's' :
-
{
-
nResult = a_nFirst - a_nSecond;
-
break;
-
}
-
-
case'm' :
-
{
-
nResult = a_nFirst * a_nSecond;
-
break;
-
}
-
-
case'd' :
-
{
-
nResult = a_nFirst / a_nSecond;
-
break;
-
}
-
-
case'q' :
-
{
-
// To quit the recursive.
-
break;
-
}
-
-
default:
-
{
-
cout << "Please enter the correct operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> a_cOperation;
-
-
// Recursive function to do the operation again.
-
nResult = DoOperation(a_nFirst, a_nSecond, a_cOperation);
-
break;
-
}
-
}
-
return nResult;
-
}
-
-
void main()
-
{
-
int
-
nFirst = 0,
-
nSecond = 0,
-
nResult = 0;
-
char
-
cOperation = '\0';
-
-
// Get the first number.
-
cout << "Enter the first number : ";
-
cin >> nFirst;
-
-
// Get the second number.
-
cout << "Enter the second number : ";
-
cin >> nSecond;
-
-
// Get the operator.
-
cout << "Enter the operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> cOperation;
-
-
// Do the operation with the given information.
-
nResult = DoOperation(nFirst, nSecond, cOperation);
-
-
// Print the result.
-
cout << "The result is : " << nFirst << " " << cOperation << " " << nSecond << " = " << nResult;
-
-
}
-
-
Regards,
M.Sivadhas.
-
-
{ while(1)
-
{
-
switch(ch) {
-
case'a' :
-
result=number1+numder2;
-
break;
-
case's' :
-
result=number1-number2;
-
break;
-
case'm' :
-
result=number1*number2;
-
break;
-
case'd' :
-
result=number1/number2;
-
break;
-
default:
-
printf("please enter the correct character");
-
break;
-
} /*end of while*/
-
int DoOperation(int a_nFirst, int a_nSecond, char &a_cOperation)
-
{
-
int
-
nResult = 0;
-
-
switch(a_cOperation)
-
{
-
case'a' :
-
{
-
nResult = a_nFirst + a_nSecond;
-
break;
-
}
-
-
case's' :
-
{
-
nResult = a_nFirst - a_nSecond;
-
break;
-
}
-
-
case'm' :
-
{
-
nResult = a_nFirst * a_nSecond;
-
break;
-
}
-
-
case'd' :
-
{
-
nResult = a_nFirst / a_nSecond;
-
break;
-
}
-
-
case'q' :
-
{
-
// To quit the recursive.
-
break;
-
}
-
-
default:
-
{
-
cout << "Please enter the correct operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> a_cOperation;
-
-
// Recursive function to do the operation again.
-
nResult = DoOperation(a_nFirst, a_nSecond, a_cOperation);
-
break;
-
}
-
}
-
return nResult;
-
}
-
-
void main()
-
{
-
int
-
nFirst = 0,
-
nSecond = 0,
-
nResult = 0;
-
char
-
cOperation = '\0';
-
-
// Get the first number.
-
cout << "Enter the first number : ";
-
cin >> nFirst;
-
-
// Get the second number.
-
cout << "Enter the second number : ";
-
cin >> nSecond;
-
-
// Get the operator.
-
cout << "Enter the operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> cOperation;
-
-
// Do the operation with the given information.
-
nResult = DoOperation(nFirst, nSecond, cOperation);
-
-
// Print the result.
-
cout << "The result is : " << nFirst << " " << cOperation << " " << nSecond << " = " << nResult;
-
-
}
-
I got the following errors
-fatal error C1004: unexpected end of file found
Error executing cl.exe.
-error C2447: missing function header (old-style formal list?)
-
-
{ while(1)
-
{
-
switch(ch) {
-
case'a' :
-
result=number1+numder2;
-
break;
-
case's' :
-
result=number1-number2;
-
break;
-
case'm' :
-
result=number1*number2;
-
break;
-
case'd' :
-
result=number1/number2;
-
break;
-
default:
-
printf("please enter the correct character");
-
break;
-
} /*end of while*/
-
int DoOperation(int a_nFirst, int a_nSecond, char &a_cOperation)
-
{
-
int
-
nResult = 0;
-
-
switch(a_cOperation)
-
{
-
case'a' :
-
{
-
nResult = a_nFirst + a_nSecond;
-
break;
-
}
-
-
case's' :
-
{
-
nResult = a_nFirst - a_nSecond;
-
break;
-
}
-
-
case'm' :
-
{
-
nResult = a_nFirst * a_nSecond;
-
break;
-
}
-
-
case'd' :
-
{
-
nResult = a_nFirst / a_nSecond;
-
break;
-
}
-
-
case'q' :
-
{
-
// To quit the recursive.
-
break;
-
}
-
-
default:
-
{
-
cout << "Please enter the correct operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> a_cOperation;
-
-
// Recursive function to do the operation again.
-
nResult = DoOperation(a_nFirst, a_nSecond, a_cOperation);
-
break;
-
}
-
}
-
return nResult;
-
}
-
-
void main()
-
{
-
int
-
nFirst = 0,
-
nSecond = 0,
-
nResult = 0;
-
char
-
cOperation = '\0';
-
-
// Get the first number.
-
cout << "Enter the first number : ";
-
cin >> nFirst;
-
-
// Get the second number.
-
cout << "Enter the second number : ";
-
cin >> nSecond;
-
-
// Get the operator.
-
cout << "Enter the operator(a -> add, s -> sub, m -> mul, d -> div, q -> quit : ";
-
cin >> cOperation;
-
-
// Do the operation with the given information.
-
nResult = DoOperation(nFirst, nSecond, cOperation);
-
-
// Print the result.
-
cout << "The result is : " << nFirst << " " << cOperation << " " << nSecond << " = " << nResult;
-
-
}
-
I got the following errors
-fatal error C1004: unexpected end of file found
Error executing cl.exe.
-error C2447: missing function header (old-style formal list?)
Hi,
Remove your while loop. -
{ while(1)
-
{
-
switch(ch) {
-
case'a' :
-
result=number1+numder2;
-
break;
-
case's' :
-
result=number1-number2;
-
break;
-
case'm' :
-
result=number1*number2;
-
break;
-
case'd' :
-
result=number1/number2;
-
break;
-
default:
-
printf("please enter the correct character");
-
break;
-
} /*end of while*/
-
-
Regards,
M.Sivadhas.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Google Mike |
last post by:
This is big news!
http://story.news.yahoo.com/news?tmpl=story&ncid=1817&e=8&u=/zd/20050225/tc_zd/146644&sid=96120751...
|
by: Numberwhun |
last post by:
Hello everyone! I am trying to learn java and have run into kind of a
snag. Here is the code that I have so far:
------ <begin_code> ----------
import javax.swing.*;
import...
|
by: HolaGoogle |
last post by:
Hi all,
Please help me with the following..it's realy urgent and i tried
everything i could and i can't get it work properly!! Thanks in
advance.
Here's what i'm trying to accomplish:
in my...
|
by: s_erez |
last post by:
Hi,
This is a realy tricky one.
I have an ASP.NET application where some pages are reading data from a
DB and presenting reports.
In order for the user to wait while the page is reading data from...
|
by: dave |
last post by:
Hi guys
I display one page in popup window...that fetches some data from sql and
perfom some calculation (tht approx 10 secs) and display result....
I am trying to display "Please wait ..."message...
|
by: rked |
last post by:
I get nameSPAN1 is undefined when I place cursor in comments box..
<%@ LANGUAGE="VBScript" %>
<% DIM ipAddress
ipAddress=Request.Servervariables("REMOTE_HOST")
%>
<html>
<head>
<meta...
|
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>...
|
by: pshindle |
last post by:
DB2 Team -
I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for
Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack
files to a CD. I proceded to install this...
|
by: PEB |
last post by:
POSTING GUIDELINES
Please follow these guidelines when posting questions
Post your question in a relevant forum
Do NOT PM questions to individual experts - This is not fair on them and...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| | |