-
Coding Error
Hey. Im struggling with my first real program. Its real basic but it will be funny. Can sum1 look at it and fix it?
Code:
#include <iostream.h>
int fav(int x);
int main()
{
int x;
int random(101);
x=random(101);
{
cout<<"Please hit Enter when you are ready to hear your fortune";
}
if(x>1&&<11)
{
cout<<"You will be a loner for ever!";<<fav(x)
}
else if(x>=11&&<21)
{
cout<<"You may meet a mole!";<<fav(x)
}
else if(x>=21&&<31)
{
cout<<"Dont expect much, but you may get lucky.";<<fav(x)
}
else if(x>=31&&<41)
{
cout<<"You will meet a good housewife, then get divorced, driving you broke!";<<fav(x)
}
else if(x>=41&&<51)
{
cout<<"You will meet a good slut";<<fav(x)
}
else if(x>=51&&<61)
{
cout<<"You are likely to get laid a fair bit!";<<fav(x)
}
else if(x>=61&&<71)
{
cout<<"You will meet a hot person with nice rack, but she only married you for money!";<<fav(x)
}
else if(x>=71&&<81)
{
cout<<"You will be a porn star";<<fav(x)
}
else if(x>=81&&<91)
{
cout<<"Expect a good root all the time!";<<fav(x)
}
else if(x>=91&&<101)
{
cout<<"You will be a cuban I am sillyI am sillyI am sillyI am silly master!";<<fav(x)
}
else if(x<0)
{
cout<<"You will be a virgin and a prostitute wouldnt screw you if you paid her!";<<fav(x)
}
int fav(int x)
{
return x;
}
}
thankz ;)
-
Inside your if expressions is where your problem is.
Code:
else if(x>=81&&<91)
is wrong. Change it to:
Code:
else if(x>=81 && x<91)
-
Also remove the line that reads
-
Another problem:
You cant put a function inside another function like that. Move the fav() function outside:
Code:
int fav(int x);
int main()
{
// main code here
}
int fav(int x)
{
return x;
}
-
Couple more things (sorry, for the multiple posts):
You should probably change your include to :
Code:
#include <iostream>
iostream is the standard library, where iostream.h is the depreciated library.
Also your main() function should return something (just return 0 at the end). Most compilers will let you get away without returning something, but in reality it's best to have the program return a value.
-
Well I see alot of errors I would recommed normally that you look at your compiler output but since your new :) also for future refenece don't ever expect someone here to "fix" your code we are just here to help you along not do the work for you but i remeber how it fells to be new.
Code:
#include <iostream>
#include <cstdio>
using std::cout;
using std::cin;
int main()
{
srand(time(NULL));//To give you random numbers based on the time
int x = rand()%101 ;//random number between 1 and 100
//int random(101); was not needed
cout<<"Please hit Enter when you are ready to hear your fortune";
cin.get();//so you actully have to hit enter
//needed to add the x to the other side
if(x>1&&x<11)
{
cout<<"You will be a loner for ever!";//these arn't needed <<fav(x)
}
else if(x>=11&&x<21)
{
cout<<"You may meet a mole!";
}
else if(x>=21&&x<31)
{
cout<<"Dont expect much, but you may get lucky.";
}
else if(x>=31&&x<41)
{
cout<<"You will meet a good housewife, then get divorced, driving you broke!";
}
else if(x>=41&&x<51)
{
cout<<"You will meet a good slut";
}
else if(x>=51&&x<61)
{
cout<<"You are likely to get laid a fair bit!";
}
else if(x>=61&&x<71)
{
cout<<"You will meet a hot person with nice rack, but she only married you for money!";
}
else if(x>=71&&x<81)
{
cout<<"You will be a porn star";
}
else if(x>=81&&x<91)
{
cout<<"Expect a good root all the time!";
}
else if(x>=91&&x<101)
{
cout<<"You will be a cuban I am sillyI am sillyI am sillyI am silly master!";
}
else if(x<0)
{
cout<<"You will be a virgin and a prostitute wouldnt screw you if you paid her!";
}
/* This function has no use what so ever
int fav(int x)
{
return x;
}*/
cin.get();//waits for enter agian
return 0;
}
Welcome :)
-