> Need help with c++ programming?

Need help with c++ programming?

Posted at: 2014-12-18 
create an array of 3 elements, '*', '@', '%'

loop from 0 to user_input-1

print string [loop_iterator % 3]

so if your loop # is 4, mod 3 results in 1, which means the 2nd element of the array is printed. (remember that arrays are 0 based, so your positions are 0,1, and 2.

User enters 4

first iteration of loop, iterator is 0.

it prints the 0 element of the array.

next loop iterator is 1, it prints the 1 element of the array

... loop 6, iterator is 5. 5 mod 3 is 2. It prints the char in the 2 position of the array.

This is what the directions said: Write a C++ program that reads a number from a user.

If the number is negative or zero, display an error message. Otherwise, your program should draw a line

that alternates between displaying asterisks (*), at-signs (@ ), and ampersands (&) up to the number

entered by the user.

A sample run of your program might look like this.

Enter a number: 5

* @ & * @

This is another sample run of your program

Enter a number: 8

* @ & * @ & * @

Make an array like so: char a[ '*', '@', '&'];

Then have the user enter an number, say 5, then using a loop start printing out the array. Print out the first character, then loop and print out the second , then loop for the third, then loop for the fourth then ...... oh wait, there is no forth character! So then reset and continue printing the first character then loop for the second then stop because we just printed out 5.

Nuff said.

ultimate lazy proscrastination method here

#include

using namespace std;

int main(void){

int variableCounter;

cin >> variableCounter;

variableCounter /= 3;

for (int i = variableCounter; i >= 0; i--){

cout << "*@%";

}

return 0;

}

note that numbers will likely be truncated if not divisable by 3, but who cares lol.

#include

int main(void){

char o[]={"*@&"};

int n=7;

for(int j=0;j
cout << o[j%3];

return 0;

}

I'm new to programming and I have to write a code that alternates the symbols *, @, and & for the number given. For example, if the user input the number 5, then the output is:

* @ & * @