Hello
I'm new to c++ and relatively new to programming
i need to write a program that displays either a random number or a random letter
here is my code
#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
int main()
{
int y = rand () % 3 + 1;
int n = rand() % 26;
char c = (char)(n+65);
srand ( time(NULL) );
{
if ( y=1 )
{cout << rand() % 10 + 0;}
else
{cout << c << endl;}
}
}
whem i compile it only displays a random number... where did i go wrong
... oh and sorry for my formating
You have to remember that all of the "numbers" you see have ASCII representations as characters so simply casting a number to a character could potentially display a number. Here's a link to a copy of the ASCII chart: http://www.asciitable.com/