if(num == randnum)
{
printf("Excellent! You guessed the number with %d tries!\n\n", tries );
printf("Would you like to play again (y or n)? ");
scanf("%c", &choice);
THE CODE IS DONE THIS FAR BUT HOW TO GET CHAR INPUT ie y/n :
if (choice == n )
THIS IS THE WAY I AM TRYING BUT IT IS NOT WORKING.....
#include <iostream>
int main()
{
char choice = 'y';
while (choice != 'n')
{
//////////////////////////////////
// Your random guess code here. //
//////////////////////////////////
std::cout << "Would you like to play again? (y/n): ";
std::cin >> choice; // If you enter anything but 'n' it will repeat.
}
}
exit, and goto are not good, even in C. There should be nothing wrong with choice == 'n'. It means that you've probably not declared choice as you've stated above or maybe you have brackets that aren't in the right place, or maybe it's not inside a function, or there could be any number of things wrong with that line. The == operator itself is not wrong. We'd have to see the code to tell you exactley what is wrong.
Use this then:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <stdio.h>
int main()
{
char choice = 'y';
while (choice != 'n')
{
//////////////////////////////////
// Your random guess code here. //
//////////////////////////////////
printf("Would you like to play again? (y/n): ");
scanf("%c",&choice); // If you enter anything but 'n' it will repeat.
}
}