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

  Write a program the contains an array of 1000 elements name

Write a function named equals() that accepts two char arrays and return true if both arrays have the same characters in the same order. The function should return false otherwise. Write a simple main() function to test your function.

  A perfect solution is impossible or too expensive

Optimization is often encountered in engineering problems. More often than not, a perfect solution is impossible or too expensive to find and implement. Therefore, we resort to sub-optimal, yet useful, solutions. This assignment tackles a classical p..

  Implement circular linked list in c program

implement circular linked list in c program in the best possible easiest way.

  Implement a simplified version of the set class

You will implement a simplified version of the set class. You must implement all functions defined in the provided file set.h. You may add other member functions and variables as necessary.

  Write an input validation loop

write an input validation loop that asks the user to enter a number in the range of 1 through 4.

  Containing all the genes in the dna sequence

As described above plus an integer reference parameter, and return a dynamically-allocated array of strings containing all the genes in the DNA sequence. Each string in the array will contain a unique

  50 element array of integers with random numbers

write a java code to instantiate and initialize a 50 element array of integers with random numbers in the range of 45 through 256 inclusive.

  Const int num_years

How do you get this program to get both player input and then display results(As described on bottom) #include  const int NUM_YEARS=15;//The number of years const int NAME_SIZE=32;//The max size of the player name string

  Program to translates letter grade into number grade

In C++ (should be able to compile in Visual Studio 2010): Write a program to translates letter grade into number grade. Letter grades are A,B,C,D and F, possibly followed by a + or -.

  Implement the vector class using inheritance

Is it better to implement the Vector class using inheritance (is-a relationship) or composition (has-a relationship). In other word, which one of the following gives a better implementation?

  Program to check compatibity for matrix multiplication

Write down program in C++ for matrix multiplication. Program must accept dimension of both matrices to be multiplied and check for compatibity.

  Use a for loop to generate 100 random numbers.

Use a For Loop to generate 100 random numbers. Determine the most current maximum and minimum number as the random numbers are being generated. This is referred tp as a "running" maximum and minimum. Display the running maximum and minimum values as ..

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