Code in c++ Write a program that administers a short, if unscientific, personali
ID: 3671508 • Letter: C
Question
Code in c++ Write a program that administers a short, if unscientific, personality test, scores the test, and determines whether or not the user's personality is Type A, Type B. or somewhere in between. The program should prompt the user to answer each of the eight questions with a number between the range of 1-5 where 1 means Never and 5 means always. The eight questions are: id am competitive I am annoyed by people who arc late for appointments I perform several tasks simultaneously I am ambitious I rush to get tasks completed I worry about the future l am in a race with time I speak very rapidly If the score is in the range of 35-40 Type A. 21-34 Between A and B. tending towards A, 12-20 Between A and B. tending towards B. 8-11 Type B. You should find someone to take your test and print out their score. The person that took your test must sign the paper and the paper will be turned in at the beginning of class.Explanation / Answer
Following code runs fine in windows environment. Compiler may display 'warnings' regarding deprecated use of character pointer,but it should not cause any problem
Guidelines are provided as comments in program
code:
# include <iostream>
using namespace std;
int main()
{
cout<<"***** Personality Test ***** Please answer the following questions with a number range betwwen 1-5 where 1 means Never and 5 means always ";
/*Storing questions as array of character pointers,where each pointer points to a question!*/
char *q[]={"I'm Competative'","I'm annoyed by people who're late for appointments","I perform several tasks simultaneously","I'm ambitious","I rush to get task completed","I worry about the future","I'm in a race with time","I speak very rapidly"};
/*'sum' is for storing sum of answers given and 'a' is to store current answers*/
int sum=0,a;
//for loop iterate through all the 8 questions
for(int i=0;i<8;i++)
{
/*following infinite for loop doen't end, until user provides answer within range*/
for(;;)
{
cout<<" "<<i+1<<". "<<q[i]<<" :";
cin>>a;
if(a<1 || a>5) cout<<" Please answer withing the range ";
else { sum=sum+a; break; }
}
}
cout<<" Personality test results: ";
if(sum>=35) cout<<"Personality Type A";
else if(sum>=21) cout<<"Personality Type between A & B,tending towards A";
else if(sum>=12) cout<<"Personality Type between A & B,tending towards B";
else cout<<"Personality Type B";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.