so i have a class assignment , and i have to create a class assignment to make a c++ program which makes the user write 3 number then the program will arrange them from smallest to largest , i have to accord for all situation like if the user types in 2 same one wrong or if the user types in a letter , im only allowed to use if and else if along with variables ,'and' and ' or ' are not allowed so my problem is i don't understand whats wrong with my program
Your indentation is all over the place and makes what should be simple logic really hard for us to read. Also, darn, what kind of insane teacher doesn't allow basic logic operations?
You have at least 18 if-branches -- more than the possible number of outcomes! I think you are over-complicating this.
Are you allowed to use the + and - symbols in your program? If so, I have a nice solution.
#include <iostream>
int main()
{
int first, second, third ;
std::cout << "enter three numbers\n" ;
// accord for all situation like if the user types in a letter
if( std::cin >> first >> second >> third ) // if three numbers were read
{
// only allowed to use if and else if along with variables,
// 'and' and ' or ' are not allowed
// if first is greater than second, swap the two
if( first > second )
{
constint temp = first ;
first = second ;
second = temp ;
}
// after this, second is greater than or equal to first
// if second is greater than third, swap the two
if( second > third )
{
constint temp = second ;
second = third ;
third = temp ;
}
// after this, third is greater than or equal to second
// if first is greater than second, swap the two
if( first > second )
{
constint temp = first ;
first = second ;
second = temp ;
}
// after this, second is greater than or equal to first
// (third was already greater than or equal to second)
std::cout << "the numbers in ascending order: "
<< first << ", " << second << ", " << third << '\n' ;
}
else // the user typed in a letter instead of a number
{
std::cout << "error: invalid input\n" ;
}
}