How can I create a program where the output is name,horoscope,birthdate and birthstone..

Dani AI

Generated

A few practical notes before a complete example.

The problems in the thread come from small but important mistakes: using a single char for a full name, relying on fflush(stdin), and a few syntax/indexing errors. 's snippet will only read one character. was on the right track with an indexed approach but had typos and an indexing logic issue. Use std::string + std::getline for names, validate month/day numbers, and determine zodiac by checking date ranges (not by simple arithmetic on the month index). Also be careful when mixing getline and operator>> — clear the input buffer or read consistently.

A compact, working example that reads a full name, validates month/day, maps month to a birthstone, computes zodiac sign, and prints a short horoscope:

#include <iostream>
#include <string>
#include <array>

std::string zodiac(int m, int d) {
  if ((m==3 && d>=21) || (m==4 && d<=19)) return "Aries";
  if ((m==4 && d>=20) || (m==5 && d<=20)) return "Taurus";
  if ((m==5 && d>=21) || (m==6 && d<=20)) return "Gemini";
  if ((m==6 && d>=21) || (m==7 && d<=22)) return "Cancer";
  if ((m==7 && d>=23) || (m==8 && d<=22)) return "Leo";
  if ((m==8 && d>=23) || (m==9 && d<=22)) return "Virgo";
  if ((m==9 && d>=23) || (m==10 && d<=22)) return "Libra";
  if ((m==10 && d>=23) || (m==11 && d<=21)) return "Scorpio";
  if ((m==11 && d>=22) || (m==12 && d<=21)) return "Sagittarius";
  if ((m==12 && d>=22) || (m==1 && d<=19)) return "Capricorn";
  if ((m==1 && d>=20) || (m==2 && d<=18)) return "Aquarius";
  if ((m==2 && d>=19) || (m==3 && d<=20)) return "Pisces";
  return "Unknown";
}

std::string birthstone(int m) {
  static const std::array<std::string,13> s = {"",
    "Garnet","Amethyst","Aquamarine","Diamond","Emerald","Pearl",
    "Ruby","Peridot","Sapphire","Opal","Topaz","Turquoise"};
  return (m>=1 && m<=12) ? s[m] : "Unknown";
}

Troubleshooting tips: validate the day against the month (April has 30 days, February 28/29), and handle bad numeric input with cin.clear() + cin.ignore(). For fuller horoscopes, keep messages in a file or a std::map (so they are easy to edit). Use the example above as a base and extend it to handle cusps, localization, or more detailed horoscope text.

#include <iostream>
using namespace std;
int main()
{
char name;
cout << "Please Enter Name" << endl;
cin >> name;

cout << "Your name is" << name << endl;
cin.get();
fflush(stdin);
return 0;
}

thanks for the reply..but I need the whole code including the output of zodiac sign/horoscope,birthday and birthstone..thanks again..

int sign,month,day;
char zodiac description[12],name[20];

int main(){

cout<<"Write your name"<<endl;
cin>>name;
cout<<"When did you born"<<"Wirte the number of the month"<<endl;
cin>>month;
cout<<"Write Day"<<endl;
cin>>day

cout<<"Your name is : "<<name<<"Your bithday is: "<< month<<" "<<day<<endl;
cout<<zodiac description[12-month]<<endl;
return o;
}

hi there..thanks for this code..I already try this one a while ago, there's a lot of error..here's the output of that code ..

write your name
jj
When did you bornWirte the number of the month
08
Write Day
09
name is jjday is month 9
zodiac description[12-month]

that's the output friend..
I think you forgot to write the other cod..:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.