I want to create a program that draws a rectangle or a square based on what the user answers to the initial question. If you type c
, then draw the square on a tab thanks to the gfx library. If he answers r
, draw the rectangle.
My problem is that I don't know how to make it detect if you have entered that " c
" or " r
" and then continue with what I'm looking for.
#include <iostream>
#include <cmath>
#include "gfx.h"
using namespace std;
int main(){
char c;
char r;
cout << "¿Quieres dibujar un cuadrado o un rectángulo?(C/R): ";
cin >> "C o R";
if (c){
cout << "Has pedido un cuadrado." << endl;
} else if(r){
cout << "Has pedido un rectángulo.";
} else{
cout << "No has introducido ni C ni R :(";
}
return 0;
}
To read from the console, you must use
std::cin
but into a variable: