I'm doing this in ***Visual Studios: Visual C++/win32/Win32 Console Application***
I'm aware that it looks more like C. I tried using the variables in my C++ book, But the program didn't read them. Is there a different #Include I should be using so it works? What should I be using instead of Int, Char, Printf,
or scanf?
One of three things happen depending how I edit the code:
- I am able to enter in Player 1s input, but it skips over the rest and registers their names as numbers. So at the end it would say ***"0, your score was 14"*** instead of ***"JJ, your score was 14"***
- I am able to enter the first and second player names, but then it crashes.
- It goes straight to crashing as soon as I open it.
What I want to happen:
- Ask the user to input the names of 3 players.
- Assign a random score for each player
- Display, from highest to lowest score, the names and scores of the player.
(Player 3 your score 5, player 1 you scored 3, player 2 you scored 0)
Program does ask the question for 1 or 2 players before crashing. It can also display the score in order if it skips over asking the players their names.
Mind taking a look to see where I'm going wrong? Below is the code:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
char p1;
char p2;
char p3;
int p1n = rand() % 100 + 1;
int p2n = rand() % 100 + 1;
int p3n = rand() % 100 + 1;
char answer;
int main(){
printf("Player 1, Please enter your name: \n");
scanf_s("%s", p1);
printf("QUICK! Kill some things..\n");
printf("PEW PEW PEW\n");
printf("*Que dramatic blood splatter...*\n");
printf("\n");
printf("Player 2, Please enter your name: \n");
scanf_s("%s", p2);
printf("SAVE THE USELESS PRINCESS!\n");
printf("Throw some uh Pizz ah.\n");
printf("Move along, There's no violence in this game.\n");
printf("Go sit on some turtles.\n");
printf("\n");
printf("Player 3, Please enter your name: \n");
scanf_s("%s", p3);
printf("Take control and go be a criminal.\n");
printf("*Hint Hint*\n");
printf("Run over some pedestrians.\n");
printf("The Po-Pos hate when you run over pedestrians.\n");
printf("\n");
return 0;
}