Supposed to swap numbers

Assignment Help C/C++ Programming
Reference no: EM13165682

The program is supposed to swap numbers, but I am stuck something is wrong! It does not swap them it repeats the second number, please help to fix! Thanks, this is in C++.

Code Below:

// This program takes two values from the user and then swaps them
// before printing the values. The user will be prompted to enter
// both numbers.


#include <iostream>
using namespace std;

int main()
{
     float firstNumber;
     float secondNumber;

     // Prompt user to enter the first number.
     cout << "Enter the first number" << endl;
     cout << "Then hit enter" << endl;
     cin >> firstNumber;

     // Prompt user to enter the second number.
     cout << "Enter the second number" << endl;
     cout << "Then hit enter" << endl;
     cin >> secondNumber;

     // Echo print the input.
     cout << endl << "You input the numbers as " << firstNumber << " and " << secondNumber << endl;

     // Now we will swap the values.
     firstNumber = secondNumber;
     secondNumber = firstNumber;

     // Output the values.
     cout << "After swapping, the values of the two numbers are " << firstNumber << " and " << secondNumber << endl;
     return 0;
}

Reference no: EM13165682

Questions Cloud

What would be the ieee 754 double precision binary : What would be the IEEE 754 double precision binary representation of the floating point value 2.71828×10-13? Express your final answer as a 16-hexdigit number and explain how your answer was obtained for full credit.
Search for the value needle in the array : Search for the value needle in the array range given by [hay_begin ... hay_end), using the Linear Search algorithm. This function will return a pointer to the needle value if it is found, or a null pointer if needle is not found.
A java program where the user designates : a java program where the user designates how many games they would like to play (for example user inputs 10 games) then they play the game, if lets say there is a tie after 10 games the game continues until either the user of the computer wins by 2
What happens when you assign : What happens when you assign 340,282,343,598.33 to a Single variable? Assuming that the variable in question is named sngNumber and you execute the statement MessageBox.Show
Supposed to swap numbers : The program is supposed to swap numbers, but I am stuck something is wrong! It does not swap them it repeats the second number, please help to fix! Thanks, this is in C++.
The imperial system of measurements : The Imperial system of measurements uses feet and inches for length, where 1 foot is equal to 12 inches. Write a class named Imperial that will represent distance measurements in feet and inches. Your class should include the following.
What do the loops print : What do the following loops print? Work out the answer by tracing the code, not by using the computer. a. int s = 1; for (int n = 1; n
The ieee 754 single precision binary representation : What would be the IEEE 754 single precision binary representation of the floating point value -314159265. 3589 ? Express your final answer as an 8-hex-digit number and explain how your answer was obtained for full credit.
Child process to take the role of the number guesser : Write a program in C that takes a number between 1 and 1024 as input on the command line, and then forks a child process to take the role of the number guesser

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Repeat these questions by writing functions

Repeat these questions by writing functions that receive the arrays as constant reference parameters and return the appropriate values through the function name (via return statement). The function header could look like:

  Add the correct code to fill the matrix array with the value

Use the file below code and add the correct code to fill the matr2 array with the values that make it the matrix transpose of matr1. There are many examples on the Internet that show how to do this in C++ and what it should look like when it is corre..

  Write a loop that fills a vector

Write a loop that fills a vector V with ten  different  random numbers between 1 and 100. output must actually display the random numbers to get credit.

  Represent an instruction supported by simpletron

Implementation contains a Simpletron class and several supporting Instruction classes

  Write the class definition for a class called complex

. Write the class definition for a class called complex.

  Include a main function that will solicit

Include a main function that will solicit a DNA sequence string from the user, call the genes function to obtain all the genes in the sequence and print each one on the console display

  Design in c a unix utility program gasp

Design in C a Unix utility program gasp. Command gasp [options] STRING FILE... must read listed files (FILE...) and copy each line from input to stdout if it contains STRING.

  Develop a two dimensional interactive game

The player starts as a disk, but can "morph" (that is expand and contract) in selected directions

  Data from the file grocery.dat

Read the data from the file Grocery.dat and assign values to the 10  GroceryItem  objects. Next display these items to allow a customer to select grocery items from the list and indicate the quantity of that item he or she would like to order. When t..

  Write c program to add two integers and prints out average

Write a C program that prompts for a variable number of integers, adds them up, and prints out the average. The user will enter either an integer to be averaged.

  Program calculates and displays salesperson''s commission

The sales manager at Tompkins Company wants a program that calculates and displays each salesperson's commission, which is 10% of his or her sales. It also should display the total commission. Use a value-returning function to get the amount sold by ..

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd