output position

i want to how to make the output dependent on its each individual input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  #include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;

int main()
{
  srand(time(0));
  int r = rand();
  char a,e,i,o,u;
  int c = r % 40 + 1;
  int v = r % 40 + 41;
  int b = r % 40 + 81;
  int n = r % 40 + 121;
  int m = r % 40 + 161;
  cout <<"This program plays a simple random number game.\n";
  cout <<"Enter 5 vowel characters(a,e,i,o,u) separated by space: ";


  if (cin>>a)
    a = c ;
  if (cin>>e)
    e = v ;
  if (cin>>i)
    i = b;
  if (cin>>o)
    o = n;
  if (cin>>u)
    u = m;
    cout <<"The random numbers are "<< c <<" "<<v <<" "<< b<<" " << n<<" " << m;
    return 0;
  }

if you run this those codes , you can see that when enter 5 different vowels a, e ,i , o ,u in different position like e ,i ,a u, o the output of the program still stick to the format "a, e,i o ,u" not "e ,i , a ,u ,o" so is there anyway so that outputs of this are in same position as e,i,a,u,o not a,e,i,o,u.
An expression like this:
if (cin>>a)
returns true if ‘std::cin’ has correctly read the user input and stored it into variable ‘a’. If the operation failed, it becomes false.
So its true/false value doesn’t change according to the value the user types, but only whether the reading operation is successful or not.
Of course, the operation success or failure is determined by the user ‘wisdom’: it s/he types a negative value where only positive integers are allowed, that wrong value will cause a failure - in this sense the user input may change the final result.

So what you need to do is input the value inside a ‘char’ and then compare the content of that char to... (the values you want to compare it to).

Furthermore: if you declare a variable like this:
char a;
that variable can contain every sort of character. Its name is ‘a’, but its content can be ‘c’, ‘x’, ‘:’, ‘(’, ‘ ’... A large variety of characters. You can’t be sure of its content before having explicitely stored a value in it:
char a = 'T';
Topic archived. No new replies allowed.