Click here to Skip to main content
14,838,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I decided to make a storyboard. If you don't know what that is, It's a story that let's you makes choices, and changes based on your choices.
C++
#include <stdio.h>

int main(void) 
   {
   char characterName[100];
   int aa;
   printf("Hello. This code will write a story, based on your choice.\n");
   printf("What is the name of your character?\n");
   scanf("%s",characterName);
   printf("Your name is %s",characterName);
   printf("\n");
   printf("One day, you encounter a portal. Do you enter it %s", characterName);
   printf("?");
   printf("Enter 1 to enter it, 2 for staying");
   scanf("%i",&aa);
  if (aa == 1);
   {
   printf("You chose to stay. END OF STORY.");
   }
   if (aa == 2);
   {
     printf("You step towards the bright, purple portal.\n It looks like a swirly mirror. You are entranced as you step forward, step after step. Adventures await you.");
   }
   return 0;
   }


What I have tried:

I need help please. Can someone tell me what I am doing wrong? I know the If statement is correct, it's a error somewhere else in the code.
Posted
Updated 22-Jan-21 4:43am
v2

1 solution

Remove the semicolons:
C++
if (aa == 1);

C++
if (aa == 2);
In C / C++ semicolon is a statement terminator: so
C++
if (...);
is complete, and the next statement or statements will always be executed.

You might want to look at if ... else if ... else or switch instead of:
C++
if (...)
   {
...
   }
if (...)
   {
...
   }
It's more efficient, and easier to read when you get more than one option.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900