can someone please help me write these two little programs. If needed i can send a few bucks. 1. Write a program that requests three numbers from the user and prints out whether the numbers are the same or not. Your code may contain only one if statement. Please enter number 1: 3 Please enter number 2: 4 Please enter number 3: 3 The numbers ARE NOT the same Please enter number 1: 3 Please enter number 2: 3 Please enter number 3: 3 The numbers ARE the same 2. Write a program that requests three numbers from the user and prints out whether at least two of the numbers are the same or not. Your code may contain only one if statement . Please enter number 1: 3 Please enter number 2: 4 Please enter number 3: 3 At least two of the numbers are the same Please enter number 1: 2 Please enter number 2: 3 Please enter number 3: 4 None of the numbers are the same
So the first one is an "and" if statement, so if Number1 = Number2 and Number2 = Number3 if (Number1 == Number2 && Number2 == Number3) { //do something } else { //do something else } Code (markup): The second one is an "or" statement, if Number1 = Number2 or Number2 = Number3 or Number1 = Number3 if (Number1 == Number2 || Number2 == Number3 || Number1 == Number3) { //do something } else { //do something else } Code (markup):
thanks for the help. This is the code i got so far but it doesnt seem to be working. What am i doing wrong? #include "StdAfx.h" #include <iostream> { cout<< "Please enter number1"; cin>> Number1; cout<< "Please enter number2"; cin>> Number2; cout<< "Please enter number3"; cin>> Number3; int Number1, Number2, Number3; if (Number1 == Number2 && Number2 == Number3) cout<< the numbers are not the same; } else; { cout<< the numbers are the same; } return 0; Code (markup):
OK, I changed that one bugged example of yours to working sample. Here you have it. You can do (rewrite it to) the other versions that you need in the same fashion easily ... #include "stdafx.h" #include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int Number1, Number2, Number3; cout << "Please enter number1: "; cin >> Number1; cout << "Please enter number2: "; cin >> Number2; cout << "Please enter number3: "; cin >> Number3; if (Number1 == Number2 && Number2 == Number3) cout << "the numbers are the same"; else cout << "the numbers are not the same"; return 0; } Code (markup): Enjoy!