please help

Add a for loop that will:
 generate a number of 1's and 2's as requested by the user
 add up the number 1's and 2's generated and store the values in variables numberOfOnes and numberOfTwos

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{

int noOfValues = 0; //user is prompted for this
int value = 0; //randomly generated in the for loop. is either 1 or 2
int numberOfOnes = 0; //number of 1s generated
int numberOfTwos = 0; //number or 2s generated


//prime the random number generator so it is ready to go
srand(time(0));


cout << "Enter the number of values to generate : ";
cin >> noOfValues;

//inside a "for" loop randomly generate a 1 or 2 and count the number of 1's and 2's
//the number of times the loop iterates is determined by the number in noOfValues



//display the statistics. no changes needed
cout << fixed << showpoint << setprecision(2);
cout << "Ones generated: " << numberOfOnes << "\tPercent: ";
cout << static_cast<double>(numberOfOnes) / noOfValues * 100 << "%" << endl;

cout << "Twos generated: " << numberOfTwos << "\tPercent: ";
cout << static_cast<double>(numberOfTwos) / noOfValues * 100 << "%" << endl;;

cout << "WOW! " << endl << endl;


}
Please edit for readability.
https://www.cplusplus.com/articles/jEywvCM9/
Hello ranugive,


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



The program and comments are clear so what have you tried for

//inside a "for" loop randomly generate a 1 or 2 and count the number of 1's and 2's
//the number of times the loop iterates is determined by the number in noOfValues

?

Andy
Topic archived. No new replies allowed.