C++ Programming GalleryThe Programming Challenge

Challenge 5 – Why can’t you get the YOU GOT IT RIGHT!!!! message? in C++

Difficulty x10
x5

This Challenge was proposed for the now defunct C/C++ programming list CWORLD in 1999.
The source code of the challenge has been updated to modern C++, but maintaining the essence of the challenge, which its original author wanted to transmit.

Date: 04-IX-2000
Created by: Antonio Romeral
Challenge winner: Aurelio Márquez

  1. (and fundamental):
    • Why can’t you get the YOU GOT IT RIGHT!!!! message?
    • What is wrong and why?
  2. (secondary):
    • How should the program be changed so that it works? (i.e. so that it accepts 1.2 as a solution)

Source Code

/* CHALLENGE0005.CPP
* ==========
*
* Notes: Tested in TurboC++, BorlandC++ , DJGPP
*
* (C) Antonio Romeral 3-Sept-2000
*/

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
	float  vfloat;
	int exito = 0;

	cout << " CHALLENGE0005.CPP Guess the secret number" << endl;
	cout << " ========== (by the way, that number is 1.2)" << endl;
	cout << " (c) Antonio Romeral 3- Sept - 2000\n" << endl;

	do {
		cout << "(To give up enter 0)" << endl;
		cout << "What is the secret decimal number (between 1 and 2)? The number is: ";
		cin >> vfloat;
		cout << "\n You have entered the number: " << vfloat;

		if (vfloat == 1.2) {
			cout << ">>> YOU GOT IT RIGHT!!!! " << endl;
			exito = 1;
			break;
		}
		else {
			cout << ">>> THIS IS NOT THE NUMBER. Please try again\n" << endl;
		}

	} while (vfloat);

	cout << "\n\n\n" << endl;
	
	if (exito) 
		cout << "PERFECT. YOU ACHIEVED THE IMPOSSIBLE" << endl;
	else {
		cout << "Try again (what the hell is going on here?)" << endl;
		cout << "(pay attention... the solution is 1.2). Try again!!!" << endl;
	}

	return 0;
}

AND FINALLY I CAN ONLY SAY …. BEST OF LUCK AND MAY THE BEST CODE WIN….

If you liked this challenge remember to leave a comment in our guestbook

Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button