Question

Hello, Is anyone able to do the C++ programming for the below in visual studio. The...

Hello,

Is anyone able to do the C++ programming for the below in visual studio. The code online is giving me errors. It just needs to be very very simple as I am a beginner. I have not learned functions yet but can include the math library. I have only 1 hour. thanks

Write a program that reads from the user a positive integer (in a decimal representation), and prints its binary (base 2) representation. Your program should interact with the user exactly as it shows in the following example: Enter decimal number: 76 The binary representation of 76 is 1001100

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, d, num;
    string b;
    cout << "Enter decimal number: ";
    cin >> n;
    num = n;
    while (n > 0) {
        d = n%2;
        b = std::to_string(d) + b;
        n /= 2;
    }
    cout << "The binary representation of " << num << " is " << b << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Hello, Is anyone able to do the C++ programming for the below in visual studio. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The questions below deal with Microsoft Visual Studio 2012 Reloaded, under the Visual Basic programming language....

    The questions below deal with Microsoft Visual Studio 2012 Reloaded, under the Visual Basic programming language. The book ISBN number that I am using is: 978-1-285-08416-9 or the UPC code is: 2-901285084168-1. Question 1 Visual Basic 2012 is an object-oriented programming language, which is a language that allows the programmer to use ____________________ to accomplish a program�s goal. Question 2 An application that has a Web user interface and runs on a server is called a(n) ____________________ application. Question 3...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE INTO VISUAL STUDIO Exercise #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns...

  • Programming question. Using Visual Studio 2019 C# Windows Form Application (.NET Framework) Please include code for...

    Programming question. Using Visual Studio 2019 C# Windows Form Application (.NET Framework) Please include code for program with ALL conditions met. Conditions to be met: Word Problem A person inherits a large amount of money. The person wants to invest it. He also has to withdraw it annually. How many years will it take him/her to spend all of the investment that earns at a 7% annual interest rate? Note that he/she needs to withdraw $40,000.00 a year. Also there...

  • Needs to be done in visual studio. I keep having problems with making my own function...

    Needs to be done in visual studio. I keep having problems with making my own function to call for the statistics and the random number generator. they are both supposed to be separate functions from the main. Can anyone help? Language is C Overview: This third programming assignment will be the first to require the use of arrays. Like the second program, this program will be modular and make use of functions (including, this time, functions which process arrays). Brief...

  • If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but...

    If you’re using Visual Studio Community 2015, as requested, the instructions below should be exact but minor discrepancies may require you to adjust. If you are attempting this assignment using another version of Visual Studio, you can expect differences in the look, feel, and/or step-by-step instructions below and you’ll have to determine the equivalent actions or operations for your version on your own. INTRODUCTION: In this assignment, you will develop some of the logic for, and then work with, the...

  • Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to...

    I need some help with programming this assignment. Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...

  • // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given...

    // Write the compiler used: Visual studio // READ BEFORE YOU START: // You are given a partially completed program that creates a list of patients, like patients' record. // Each record has this information: patient's name, doctor's name, critical level of patient, room number. // The struct 'patientRecord' holds information of one patient. Critical level is enum type. // An array of structs called 'list' is made to hold the list of patients. // To begin, you should trace...

  • Hello, I am having trouble with this C++ programming assignment. If someone could write the code...

    Hello, I am having trouble with this C++ programming assignment. If someone could write the code or at least part of it that would help me, because every code I try has errors. Using if Statements, Loops and Nested Loops • Scanning Characters in a String Using a Loop • Performing Character Arithmetic In project, you will write an interactive program that, counts the number of digits in a non-negative integer, factorizes the integer into powers of ten and its...

  • Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include...

    Please use Visual Studio! Let me know if you need anything else <3 #include <stdio.h> #include <string.h> #pragma warning(disable : 4996) // compiler directive for Visual Studio only // Read before you start: // You are given a partially complete program. Complete the functions in order for this program to work successfully. // All instructions are given above the required functions, please read them and follow them carefully. // You shoud not modify the function return types or parameters. //...

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