0

C++Syntax

#include "stdafx.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main()
{
	srand(time(0));
	
	int arr[10]={0};

	for(int i=0;i<10;i++)
	{
		arr[i]=rand()%50+1;}
	
	for(int i=0;i<10;i++){

		cout<<arr[i]<<endl;
	
	}
	return 0;
}

I want to use the * to display the output, what I should improve?

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Fbody
0

>>I want to use the * to display the output,
Not entirely sure what you mean. Do you mean you want to use pointer arithmetic instead of array indices (not that there's really that big of a difference)?

i.e. use std::cout << *(anArray + anIndex); instead of std::cout << anArray[anIndex]; ???

Edited by Fbody: n/a

0

My English is not good. I want to use the "*" replace the number to display .
My assignment is that use the random 50 integer number and range from 1 to 10 and use the array to store it.Then use the"*" to display the output variable.

0

So, if the RNG generates a '5', do you want to display 5 '*' characters?
i.e. if random = 5, the output is '*****'

Or do you want to arrange several '*' characters into the shape of a 5?
something like this:

******
**
**
***** 
    **
    **
*****

??

The difference in complexity is astronomical.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.