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?
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.
I have a question on an assignment for C++. I have my code available here and...
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 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 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? #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 = "); ...
I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...
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 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...
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...
****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;...
Language is in C. Need help troubleshooting my code Goal of code: * Replace strings with a new string. * Append an s to the end of your input string if it's not a keyword. * Insert a period at the end, if you have an empty input string do not insert a period Problems: //Why does my code stop at only 2 input strings //If I insert a character my empty string case works but it's still bugged where...