I'm working on an assignment where I have to create a program that:
- Ask user for their name
- Prompts the user for # of voters
- Store user entered value
- Report errors if the user enters a negative number or a character
- seed the random number generator with the current time
-
display header for (voterCount = 0; voterCount < numVoters; voter++)
-
use random number generator to:
generate bYear (restricted between 1900 and 2000)
generate bMonth
generate bDay (limit 1 and 31)
I have the first 4 down:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
int numVoters;
char name[35]; // Variable that stores "Name" of user added max char to be 25
const int MIN_MONTH = 1;
const int MAX_MONTH = 12;
int bMonth;
cout << "Please enter your first name: ";
cin.getline(name,35); // used getline because without getline I kept getting a single char
cout << "Hello " << name << endl;
cout << "Please enter amount of voters: ";
cin >> numVoters;
while (numVoters > 0)
{
cout << "You entered: " <<numVoters << endl;
}
cout << "ERROR! ERROR! WRONG DATA TYPE PLEASE RUN THE PROGRAM
AGAIN";
return 0;
}
I don't know what to do next I've tried to continue by using what I see online but when I do I get a never-ending loop of # of voters
#include < iostream >
#include < cstdlib >
#include < time.h >
using namespace std;
int main() {
int numVoters;
char name[35]; // Variable that stores "Name" of user added max char to be 25
const int MIN_MONTH = 1;
const int MAX_MONTH = 12;
int bMonth;
cout << "Please enter your first name: ";
cin.getline(name, 35); // used getline because without getline I kept getting a single char
cout << "Hello " << name << endl;
cout << "Please enter amount of voters: ";
cin >> numVoters;
while (numVoters > 0) {
cout << "You entered: " << numVoters << endl;
}
cout << "ERROR! ERROR! WRONG DATA TYPE PLEASE RUN THE PROGRAM AGAIN";
unsigned seed = time(0); // gets current computer time
srand(seed); // seeds the random number gen
for (numVoters = 0; numVoters < 0; numVoters++)
{
bMonth = rand() % (MAX_MONTH - MIN_MONTH + 1) + MIN_MONTH;
cout << "Random month: " << bMonth << endl;
}
return 0;
}
Help with #5-7
Aucun commentaire:
Enregistrer un commentaire