personality assessment test in c++

This is a program that simulates a test regarding how girly or manly a person is. well, im the one proposed this to the professor as a project but i didnt know that it will get this hard for me. :(( I Did my best but i guess my best wasnt good enough.. since im new to c++ programming. sorry for my newbie-ness
:(((((((((((((((((((

heres my questions..
-how can i create a feature that if ever the user inputs an invalid answer.. a warning that states "invalid answer" will show up?
-and what if the answer is invalid or the user wants to change his answer?..
how can I display the previous question again?
-and, is there something wrong with my formulas? the result is always 0% for both girl and boy. how can i compute for their percentage?


#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

main()
{
int A,a; /*possible answers*/
int B,b; /*possible answers*/
int C,c; /*possible answers*/
int ans; /*input answer*/
float sum1; /*sum for Girl*/
float sum2; /*sum for boy*/
float sumG; /*sum for Girl*/
float sumB; /*sum for boy*/
sum1=0;
sum2=0;

cout<<" "<<endl<<endl;
cout<<" DO YOU SIT ON THE COUCH DAY AFTER DAY PONDERING THE AGE OLD QUESTION,"<<endl;
cout<<" DOES MY PERSONALITY FIT WITH MY GENDER?"<<endl;
cout<<" IF SO, WE HAVE JUST THE TEST FOR YOU! - THE MAN/GIRLY TEST!"<<endl;
cout<<" ASSESS YOUR MANLY AND GIRLY SIDE FROM THE COMFORT OF YOUR OWN HOME!"<<endl;
cout<<" "<<endl<<endl;
system("PAUSE");
system("CLS");
cout<<" "<<endl<<endl;
cout<<" Are You Readyyy?!?!? :DDD"<<endl<<endl<<endl;
system("PAUSE");
system("CLS");
cout<<endl<<endl<<" 1. Complete the sentence: “My handshake...”;
cout<<" A. Is enjoyable just like holding a jellyfish<<endl;
cout<<" B. Makes men cry and women quiver<<endl;
cout<<" C. Is respectable<<endl;
cout<<" Your Answer is: ";
cin>>ans;
{ if (ans=='A'||ans=='a')
{ sum1=sum1+2; }
else if (ans=='B'||ans=='b')
{ sum2=sum2+2; }
else if (ans=='C'||ans=='c')
{ sum1=sum1+1;
sum2=sum2+1; }
else /* how can i create a feature that if ever the user inputs an invalid answer.. a warning will show up? */
cout<<"invalid answer"; /* and what if the answer is invalid or the user wants to change the answer?..
how can I display the previous question again?

cout<<endl<<endl<<" 2. Your preferred mode of non-vehicular method of transportation is... "<<endl;
cout<<" A. Biking"<<endl;
cout<<" B. Running"<<endl;
cout<<" C. Walking"<<endl;
cout<<" Your Answer is: ";
cin>>ans;
{ if (ans=='A'||ans=='a')
{ sum1=sum1+2; }
else if (ans=='B'||ans=='b')
{ sum2=sum2+2; }
else if (ans=='C'||ans=='c')
{ sum1=sum1+1;
sum2=sum2+1; }
else /* how can i create a feature that if ever the user inputs an invalid answer.. a warning will show up? */
{ cout<<"Answer is Invalid"; } /* and what if the answer is invalid or the user wants to change the answer?..
how can I display the previous question again? */


sumG=(sum1/2)*100; /* is there something wrong with my formula? the result is always 0% for both girl and boy. how can i compute for their percentage? */
sumB=(sum2/2)*100; /* is there something wrong with my formula? the result is always 0% for both girl and boy. how can i compute for their percentage? */
cout.precision(2);

cout<<endl<<"Congratulations! You've finished the test!";
cout<<endl<<"Your result is.. "<<sumG<<"% GIRLY and "<<sumB<<"% MANLY.";



getch();
}
Last edited on
Well, you can make a function for every question. In that function, you actually read the input from the user and check it to see if it's ok. Also, in this function you can make those assignements with sum1, sum2, etc. I the main function you just call for those functions and that's it. I hardly recommend you to make that program in Visual C++ 2010 or later. It will be extremely nice with a GUI.
Topic archived. No new replies allowed.