I'm getting these errors:
1 IntelliSense: type name is not allowed
2 IntelliSense: expected a ')' ...............
User is supposed to roll a die, get a random number and that number is output to the screen
if the user chooses no then it says 'maybe next time'..... Here is my code.......
#include <iostream>
using namespace std;
int main (){
cout<<"Do you want to roll a 6 sided die?"<<endl;
cout<<"Enter 1 for yes or 2 for no."<<endl;
int a;
cin>>a;
if (int a=1){
int r;
do {
r=rand()%7; }
while (r==0);
switch (r){
case 1:cout<<"You got a One."<<endl;break;
case 2:cout<<"You got a Two."<<endl;break;
case 3:cout<<"You got a Three."<<endl;break;
case 4:cout<<"You got a Four."<<endl;break;
case 5:cout<<"You got a Five."<<endl;break;
case 6:cout<<"You got a Six."<<endl;break;
}
}
else {
do{
cout<<"Maybe next time."<<endl;
}
while (int a!=1);
system("pause");
return 0;
}
#include <iostream>
usingnamespace std;
int main (){
cout<<"Do you want to roll a 6 sided die?"<<endl;
cout<<"Enter 1 for yes or 2 for no."<<endl;
int a;
cin>>a;
if (a==1){
int r;
do {
r=rand()%7; }
while (r==0);
switch (r){
case 1:cout<<"You got a One."<<endl;break;
case 2:cout<<"You got a Two."<<endl;break;
case 3:cout<<"You got a Three."<<endl;break;
case 4:cout<<"You got a Four."<<endl;break;
case 5:cout<<"You got a Five."<<endl;break;
case 6:cout<<"You got a Six."<<endl;break;
}
}
else {
do{
cout<<"Maybe next time."<<endl;
}
while (a!=1);
system("pause");
return 0;
}
}
you have under cin >> a; the statement if (int a=1){ which is wrong. You are re-declaring your variable a within a condition after it's already been declared.
Also I think you know about this but use the code tags around all code please, I could have given you number line specific answers
Also, add a seed. srand(time(NULL));. You havn't generated a seed for rand() function to work with.
ok i got it to work with entering 1. if i press any other key it says maybe next time but it should only say that if i press 2, anything else it should say 'invalid'.
i got it thanks for steering me in the right direction.
and do i use code tags by the way??.....
here is my final code.....
#include <iostream>
using namespace std;
int main (){
cout<<"Do you want to roll a 6 sided die?"<<endl;
cout<<"Enter 1 for yes or 2 for no."<<endl;
int a;
cin>>a;
if (a==1){
int r;
do {
r=rand()%7; }
while (r==0);
switch (r){
case 1:cout<<"You got a One."<<endl;break;
case 2:cout<<"You got a Two."<<endl;break;
case 3:cout<<"You got a Three."<<endl;break;
case 4:cout<<"You got a Four."<<endl;break;
case 5:cout<<"You got a Five."<<endl;break;
case 6:cout<<"You got a Six."<<endl;break;
}
}
else if (a==2) {
do{
cout<<"Maybe next time."<<endl;
system("pause");
return 0;
}
while (a!=1);
}
else if (a>=3) {
cout<<"Error, please try again."<<endl;
}
system("pause");
return 0;
}