Problem with my program

when i write more than one word when asked for note it will loop forever and will only show the first word how do i fix this? i have the solutions for most of the other problems
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
string note="";
int grades();
int calculator();
int notes();
int menu= 0;
int main()
{
	system("color C8");

	while (menu == 1||menu == 2||menu == 3||menu == 0)
	{
		cout << "Welcome to TeacherHelp" << endl;
		cout << "This Program will do many things to help teachers." << endl;
		cout << "Write the number of your choice." << endl;
		cout << "[1]Calculator" << endl;
		cout << "[2]Average Grades" << endl;
		cout << "[3]Note" << endl;
		cout << note << endl;
		cin >> menu;
			switch(menu)
			{
			case 1:
				int calculator();
				break;
			case 2:
				int grades();
				break;
			case 3:
				notes();
				break;
			}
		}
	return 2182;
}
int notes()
{
	cout << "Create a note" << endl;
	cin >> note;
	return 2182;
}
Last edited on
if you want to type more than one word, use getline, if you want it to stop looping for ever, try cin.clear() and cin.ignore() after cin >> note, I forget the correct order, but clear probably goes first.
where would i put getline? and whats the syntax of it
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <string>

int grades();
int calculator();
void notes();
std::string note = "";

int main()
{
    int menu = 0;

	while (menu == 1||menu == 2||menu == 3||menu == 0)
	{
		std::cout << "Welcome to TeacherHelp" << std::endl;
		std::cout << "This Program will do many things to help teachers." << std::endl;
		std::cout << "Write the number of your choice." << std::endl;
		std::cout << "[1]Calculator" << std::endl;
		std::cout << "[2]Average Grades" << std::endl;
		std::cout << "[3]Note" << std::endl;
		std::cout << note << std::endl;
		std::cin >> menu;
		std::cin.ignore();
        switch(menu)
        {
        case 1:
            int calculator();
            break;
        case 2:
            int grades();
            break;
        case 3:
            notes();
            break;
        }
    }
	return 0;
}

void notes()
{
	std::cout << "Create a note" << std::endl;
	std::getline(std::cin, note);
}


sorry about the indentation, copy and pasting doesn't seem to work well.
Last edited on
thanks!
Topic archived. No new replies allowed.