So I am very new to writing programs and currently for my first project I am trying to write a program which will give 5 questions which you can select answer's A and B. I plan on making the answers represented by numbers 1 and 2. I then want to have the sum of the answer to give the answer of which political party that person belongs to. Any ideas how to go about this? This is what I have so far:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
char choice_letter1 = 'z';
char choice_letter2 = 'z';
char choice_letter3 = 'z';
char choice_letter4 = 'z';
char choice_letter5 = 'z';
cout << "Are you conservative or liberal?";
cout << "\n";
cout << "\n";
cout << "What is your stance on abortion?";
cout << "\n";
cout << "A. It should be legal";
cout << "\n";
cout << "B. It should be outlawed";
cout << "\n";
cout << "\n";
cout << "Should regular citizens be able to own any type of firearm?";
cout << "\n";
cout << "A. Not by any means";
cout << "\n";
cout << "B. Yes they should";
cout << "\n";
cout << "\n";
cout << "Are you in favor of any type of welfare system of any kind?";
cout << "\n";
cout << "A. Yes";
cout << "\n";
cout << "B. No";
cout << "\n";
cout << "\n";
cout << "Who would you rather vote for?";
cout << "\n";
cout << "A. Barack Obama";
cout << "\n";
cout << "B. Sarah Palin";
cout << "\n";
cout << "\n";
cout << "Would you vote for someone who was an Atheist?";
cout << "\n";
cout << "A. Yes";
cout << "\n";
cout << "B. No";
cout << "\n";
cin >> choice_letter5;
if (choice_letter5 =='a'|| choice_letter1 =='A')
{
}
return 0;
}
Keep in mind this is my first program and I'm teaching myself so please don't judge to harshly lol.
#include <iostream>
//#include <cmath> //No need for <cmath>
usingnamespace std;
int main()
{
char choice_letter1, choice_letter2, choice_letter3, choice_letter4, choice_letter5; //All on one line, and no need for declaring them :)
int total = 0; //new variable for total to determine a person's politcal view
//total is declared because otherwise it will be random number (garbage) and because the user doesn't decalare it,
//you should declare it now
//I put all of the new lines - "\n" - on the end of the strings to save lines
cout << "Are you conservative or liberal?\n\n";
cout << "What is your stance on abortion?\n";
cout << "A. It should be legal\n";
cout << "B. It should be outlawed\n\n";
cout << "Should regular citizens be able to own any type of firearm?\n";
cout << "A. Not by any means\n";
cout << "B. Yes they should\n\n";
cout << "Are you in favor of any type of welfare system of any kind?\n";
cout << "A. Yes\n";
cout << "B. No\n\n";
cout << "Who would you rather vote for?\n";
cout << "A. Barack Obama\n";
cout << "B. Sarah Palin\n\n";
cout << "Would you vote for someone who was an Atheist?\n";
cout << "A. Yes\n";
cout << "B. No\n";
cin >> choice_letter5;
if (choice_letter5 == 'a' || choice_letter5 == 'A') //if choice_letter5 equals a OR A
total += 5; //add 5
elseif (choice_letter5 == 'b' || choice_letter5 == 'B') //if it's not a OR A, is it b OR B? If so...
total -= 5; //subtract 5
else //if it is anything else
cout << "\nError. Wrong input\n";
cout << "\nYour total is " << total << "\n";
//An extra part I added to help you with your goal of determining a politcal view
if (total > 0)
cout << "\nYou are very open minded and welcoming\n";
elseif (total < 0)
cout << "\nYou are a bit closed minded. Athiests are people too :S\n";
elseif (total == 0)
cout << "\nYou made a wrong input somewhere\n";
return 0;
}
The same format would probably be fine but their outcome should probably be more intuitive.
Something to note about if-statements is that if there is more than one statement to go through once the if-statement equals true, you will need brackets.
For instance:
1 2 3
if (true)
std::cout << "Hello World\n";
std::cout << "How are you world\n"; //this isn't "inside" the if-statement
should be
1 2 3 4 5
if (true)
{
std::cout << "Hello World\n";
std::cout << "How are you world\n";
}
For input, because they are just char, you can keep using std::cin >>.