Question

I have a question on an assignment for C++. I have my code available here and...

I have a question on an assignment for C++. I have my code available here and just want someone to look over it using MS VS 2010 express, for that is what my instructor is using.

Write a program that mimics a calculator. The program should take as input two integers and the opreation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.)

//**This program is designed to emulate a calculator by allowing the input of two integers, a mathematical operation, and creating an output from what the operator requests**//


#include <stdio.h>

int main(void)
{

   //Input the first integer of the problem; example: (1 + 1); the first of the two 1's is requested//
int a;
printf("Input first integer: ");
if (1 != scanf(" %i", &a))
{
printf("Input error\n");
return 0;
}

   //Input the operation; example: -, +, *, etc//
char op;
printf("Input operation: ");
if (1 != scanf(" %c", &op))
{
printf("Input error\n");
return 0;
}

   //Input the second integer here; example: (1+1); The second of the two 1's is requested//
int b;
printf("Input second integer: ");
if (1 != scanf(" %i", &b))
{
printf("Input error\n");
return 0;
}

   //The solution to the problem entered is shown here//
printf("The solution for the information given is: %i %c %i = ", a, op, b);

if (op == '*')
printf("%i\n", a * b);
else if (op == '/')
{
if (b == 0)
printf("undefined\n");
else
printf("%i\n", a / b);
           return 0;
}
else if (op == '-')
printf("%i\n", a - b);
else if (op == '+')
printf("%i\n", a + b);
else
printf("unsupported\n");
       return 0;
}

The issue that I am having is this works perfectly in CodeBlocks compiler, but not in MS VS 2010 Express. After the problem is input in the pop-up window it stays up in CodeBlocks, but disappears in MS VS 2010 Express. I know I don't have a pause command, so I don't know why it is working in one and not the other. Also, how does my commenting look?

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
I have a question on an assignment for C++. I have my code available here and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Here is the code I have so far. I'm trying to figure out how to implement...

    Here is the code I have so far. I'm trying to figure out how to implement a boolean and use precedence. The 2nd expression should be 14 but it comes out as 28 so I'm definitely not understanding. #include <stack> #include <iostream> #include <string> using namespace std; // Function to find precedence of // operators. int precedence(char op) {    if (op == '+' || op == '-')        return 1;    if (op == '*' || op ==...

  • the coding language is just the basic c language and here is my first attempt at...

    the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...

  • C Programming Question Hi, I have the following code and in my submission I'm supposed to...

    C Programming Question Hi, I have the following code and in my submission I'm supposed to only include function definitions (i.e. implementations) in the file. However, I'm not NOT required to write the main, struct definitions and function prototypes. Could someone help me fix this code? Text Version: #include<stdio.h> #include<stdlib.h> #include <string.h> struct ip_address { int octet_1; int octet_2; int octet_3; int octet_4; }; typedef struct ip_address ip_address_t; void print_ip_address(ip_address_t ip1){ printf("%d.%d.%d.%d", ip1.octet_1,ip1.octet_2,ip1.octet_3,ip1.octet_4); } int is_valid(ip_address_t ip1){ if(ip1.octet_1 < 0...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • In the Source Folder (src) of this project create a new C source file called "gcd.c"....

    In the Source Folder (src) of this project create a new C source file called "gcd.c". Once again, copy the contents of the "main.c" file above into the "gcd.c" source file. Modify this program to NOT ask the user to input the second Positive Integer, if the user has entered a program terminating value for the "first" input Postitive Integer. #include <stdlib.h> #include <stdio.h> int main(int argc, char *argv[]) { //============================== setbuf(stdout, NULL); // turns standard output buffering off int...

  • C++ HELP I need help with this program. I have done and compiled this program in...

    C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...

  • ****Using C and only C**** I have some C code that has the function addRecord, to...

    ****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...

  • I am told to find the median of random inputs using if statements in C #include...

    I am told to find the median of random inputs using if statements in C #include <stdio.h> #include <stdlib.h> int main() { double a, b, c, d; scanf("%lf", &a); scanf("%lf", &b); scanf("%lf", &c); if (a<b && b<c) d = b; printf("%.0f\n", d); else if (b<a && a<c) d = a; printf("%.0f\n", d); else d = c; printf("%.0f\n", d); return 0; } That is my code, I keep getting an error for the else if and else saying there is no...

  • C linux please write it by only using “if and else” conditions, thanks so much this...

    C linux please write it by only using “if and else” conditions, thanks so much this is my task 3 Requirements 1. Copy your solution for Task 3 t3.c to a new file t4.c. 2. The input is guaranteed to contain at least one non-whitespace character. 3. If the input is well-formed, i.e., can be parsed to a number, the program should behave identically to Task 3. All the requirements of Task 3 still apply except the file name. 4....

  • any help! my program not working , there is an error but cannot solve it i...

    any help! my program not working , there is an error but cannot solve it i did this program after editing a previous program  and i tried to follow the following ; 1. Instead of printing the prime numbers from 2 to n, your program will print the first n prime numbers. 2. It will be an error if n is less than 1. Exampl: $ ./a 1 2 3 #include<stdio.h> 4 int p; // p is the global variable. 5...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT