Jump to content

  • Log In with Google      Sign In   
  • Create Account

First complete C++ program (simple)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Sean12111   Members   -  Reputation: 119

Like
0Likes
Like

Posted 09 December 2012 - 12:12 PM

I just began teaching myself c++ a few days ago. I decided to use what I have learned so far to create a quiz game to help me study for finals. Its a pretty simple program but its effective.

#include <iostream>

using namespace std;

int main ()
{
char Motown[100], phillysoul[100], singersongwriter[100],multiplatinum[100],Diamond[100], toasting[100],gold[100],platinum[100], ska[100], rocksteady[100], reggae[100], afterbeat[100], punk[100], newwave[100], eightyspop[100], disco[100], sixteenbeatstyle[100], AOR[100], walkman[100], sampler[100], sequencer[100];

// Motown
cout << "blend of R&B and pop\n";
cout << "based in Detroit\n";
cout << "Until 1988, largest black corporation in U.S.\n";
cout << "Started by Berry Gordy in 1959\n";
cout << "Goal:  to produce black music that would be more accessible\n";
cin >> Motown;

if(!strcmp(Motown, "motown")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - motown\n";

system ("PAUSE");
system ("cls");

//Philly soul
cout << "70s soul style\n";
cout << "Associated with producers Kenny Gamble and Leon Huff of Philadelphia International Records\n";
cin >> phillysoul;

if(!strcmp(phillysoul, "phillysoul")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - phillysoul\n";


system ("PAUSE");
system ("cls");

//Singersongwriter
cout << " musician who writes and performs own material\n";
cin >> singersongwriter;

if(!strcmp(singersongwriter, "singersongwriter")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - singersonwriter\n";


system ("PAUSE");
system ("cls");

//toasting
cout << "DJs use rhythmic patter over records\n";
cout << "originated ing jamaca. djs manipilated recoreds to make cool shit\n";
cin >> toasting;

if(!strcmp(toasting, "toasting")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - toasting\n";


system ("PAUSE");
system ("cls");

//SKa
cout << " uptempo 4 beat syle with jump band instrumentation\n";
cout << "lyrics about romantic love\n";
cin >> ska;

if(!strcmp(ska, "ska")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - ska\n";


system ("PAUSE");
system ("cls");

//rocksteady
cout << "slower, more flexible rhythm\n";
   cout << " more active bass line\n";
   cout <<" lyrics – social commentary\n";
   cin >> rocksteady;

if(!strcmp(rocksteady, "rocksteady")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - rocksteady\n";


system ("PAUSE");
system ("cls");


//reggae
cout << " mixture of Caribbean folk music and American R&B\n";
cout << "evolves from Ska and Rock Steady in Jamaica\n";
cout << "slightly faster, greater rhythmic complexity\n";
cout << "syncopated bass lines, interlocked guitar, bass and drum parts\n";
  cin >> reggae;

if(!strcmp(reggae, "reggae")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - reggae\n";


system ("PAUSE");
system ("cls");


//afterbeat
cout << "Accents in between beat\n";
cin >> afterbeat;

if(!strcmp(afterbeat, "afterbeat")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - afterbeat\n";


system ("PAUSE");
system ("cls");

//punk
cout << "reduction of rock to it’s most essential elements\n";
cout << "Saturated Rock Rhythm\n";
cout << "8 beat style dominates every instrument\n";
cout << "short repetitive songs, extremely fast tempos\n";
cout << "simple forms, harmonically simple (often I IV V)\n";
cout << "intentionally anti-commercial\n";
cin >> punk;

if(!strcmp(punk, "punk")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - punk\n";


system ("PAUSE");
system ("cls");

//newwave
cout << "More musical and more commercial evolution of punk that retained punk’s attitude\n";
cout << "influence of other styles, including Reggae\n";
cout << "lyrics in the forefront, the music enhances the words\n";
cout << "more pop influence\n";
cin >> newwave;

if(!strcmp(newwave, "newwave")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - newwave\n";


system ("PAUSE");
system ("cls");

//80spop
cout << "Influence of 70’s styles including:  punk, funk, new wave, reggae, soul\n";
cout << "Dance oriented rock\n";
cout << "16th style beat\n";
cin >> eightyspop;

if(!strcmp(eightyspop, "eightyspop")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - eightyspop\n";


system ("PAUSE");
system ("cls");

//disco
cout << "Dance music originating in gay discotheques in New York City in early 70’s\n";
cout << "four to the floor style beat – strong accent on each beat\n";
cout << "16th style beat (each beat subdivided into 4 even parts\n)";
cout << "Thinner texture than funk\n";
cout << "use of synthesizers, electronic instruments and sounds\n";
cout << "Focus on singles, not albums.\n";
cout << "12 inch 45 RPM (disco mix), longer playing, bass heavy – foundation for early rap\n";
cin >> disco;

if(!strcmp(disco, "disco")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - disco\n";


system ("PAUSE");
system ("cls");

//sixteenbeatstyle
cout << "each beat subdivided into 4 even parts\n";
cin >> sixteenbeatstyle;

if(!strcmp(sixteenbeatstyle, "sixteenbeatstyle")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - sixteenbeatstyle\n";


system ("PAUSE");
system ("cls");

//motownformula
cout << "------MOTOWN FORMULA------\n";
cout << "- song begins with intro riff\n";
system ("pause");
cout << "lead vocalist enters, soon followed by supporting backing harmonies\n";
system ("pause");
cout << "chorus builds up to title phrase which is repeated several times\n";
system ("pause");
cout << "background horns reinforce vocal harmonies\n";
system ("pause");
cout << "lush string parts soar over choruses\n";
system ("pause");
cout <<  "instrumental interlude after 2nd chorus\n";
system ("pause");
cout << "often modulating to a higher key for final choruses\n";
system ("pause");
system ("cls");

//AOR
cout << "Album-oriented Rock\n";
cout << "American FM radio format focusing on album tracks by rock artists.\n";
cin >> AOR;

if(!strcmp(AOR, "AOR")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - AOR\n";
  system ("pause");
system ("cls");
//walkman
  cout << "Allowed portable music, people could make own mixtapes\n";
  cin >> walkman;

if(!strcmp(walkman, "walkman")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - walkman\n";

  system ("pause");
  system ("cls");

//sampler
cout << "digital devices capable of recording, storing, and reproducing any sound\n";
cin >> sampler;

if(!strcmp(sampler, "sampler")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - sampler\n";

  system ("pause");
  system ("cls");

  //sequencer
  cout << "device allowing digital assembly of a song one track at a time\n";
  cin >> sequencer;

if(!strcmp(sequencer, "sequencer")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - sequencer\n";

  system ("pause");
  system ("cls");

  //gold
  cout << "sale of 500,000 units\n";
	cin >> gold;

if(!strcmp(gold, "gold")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - gold\n";

  system ("pause");
  system ("cls");

  //platinum
  cout << "Sale of 1 million units\n";
   cin >> platinum;

if(!strcmp(platinum, "platinum")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - platinum\n";

  system ("pause");
  system ("cls");

  //multiplatinum
  cout << "sale of over 2 million units\n";
  cin >> multiplatinum;

if(!strcmp(multiplatinum, "multiplatinum")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - multiplatinum\n";

  system ("pause");
  system ("cls");

  //Diamond
  cin >> Diamond;

if(!strcmp(Diamond, "Diamond")){
  cout << "Correct!\n";
}
else
  cout << "incorrect!\n";
  cout << "correct answer - Diamond\n";

  system ("pause");
  system ("cls");

  //end
  cout << "XXXXXX---GOOD LUCK---XXXXXX\n";
  system ("PAUSE");
   system ("CLS");
}


Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5434

Like
2Likes
Like

Posted 09 December 2012 - 12:17 PM

At least use stricmp to allow for capitalistaion. Consider using synonyms as well, put them in a std::map or something. 80s pop should be allowed as well as eightiespop, for example.

You should also keep score, number of correct answers and so on.

EDIT: Also use std::string rather than fixed size buffers for input. That's just asking for trouble and totally unnecessary when using console input in C++.

Edited by Paradigm Shifter, 09 December 2012 - 12:27 PM.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

#3 Josh Petrie   Moderators   -  Reputation: 3840

Like
1Likes
Like

Posted 09 December 2012 - 12:56 PM

In addition to the above, consider next learning about structures and aggregate data storage and create a structure representing a question and answer (or answer). This will vastly reduce the amount of repetition in your code.

Following that, learn about file IO and put your questions and answers in text files, then load them at runtime.

Josh Petrie | Game Developer, Undead Labs





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS