I try making a little program that sums or rests depending on user input how do I make that? ps. I want to sum/rest an integer not float
if you want to see the source code here it is:
Code:
#include <stdio.h>
#include <windows.h>
#include <string.h>
int MaxNum = 1000; //The computer will guess the number in a maximum of 10 tries
char Q [5] = "Q";
char QPH [5]; //The actual Quit the user will type in the game
char P [5] = "P";
char moreOrLess[100];
char yes [2] = "Y";
char NoItIsLess [3] = "NL";
char NoItIsMore [3] = "NM";
int num = 500;
int main()
{
system("cls");
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consoleHandle, 10);
printf(" Guess the number! \n"); //The spaces are to align it to the center
SetConsoleTextAttribute(consoleHandle, 9);
printf(" Press P to enter the game \n");
SetConsoleTextAttribute(consoleHandle, 11);
printf(" Press Q to exit the game \n");
SetConsoleTextAttribute(consoleHandle, 14);
printf(" Type Help to see the instructions (recomended for first time users) \n");
SetConsoleTextAttribute(consoleHandle, 12);
scanf("%s", QPH);
if (strcmp(Q, QPH) == 0)
{
SetConsoleTextAttribute(consoleHandle, 15);
printf(" Come back again! ");
SetConsoleTextAttribute(consoleHandle, 7);
}
if (strcmp(P, QPH) == 0)
{
SetConsoleTextAttribute(consoleHandle, 15);
printf("Think of a number from 1 to 1000 I will guess it. ");
printf("If you dont believe me lets try it...\n");
printf("The number is %d.If it is correct say Y if it is incorrect and your number is more say NM or if it is incorrect amd it is less say NL\n", num);
scanf("%s", moreOrLess);
if (strcmp (yes, moreOrLess) == 0)
{
printf("Thanks for playing");
}
if (strcmp (NoItIsLess, moreOrLess) == 0)
{
num -= 250 ; //here is where I need help
printf("The number is %d", num);
}
if (strcmp (NoItIsMore, moreOrLess) == 0)
{
num += 250 ; //and here
printf("The number is %d", num);
}
}
SetConsoleTextAttribute(consoleHandle, 7);
return 0;
}