我的代码会要求输入,但不会给出输出。 [英] My code will ask for input, but will not give output.

查看:62
本文介绍了我的代码会要求输入,但不会给出输出。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须调整已经运行的代码才能使用函数。我试图改变它并编译,但是当我输入代码和标题时,没有任何反应。没有输出。



1 * /

2 #include< iostream>

3使用命名空间std;

4 int main()

5 {

6字符串标题;

7字符代码;

8 int year;

9浮动费用;

10 cout<< 输入查看代码和查看标题。(以11个空格分隔; T,M或N<< endl;

12 cin>>代码> ;>标题;

13开关(代码)

14 {

15案'T':

16个案例't':

17弦电视(字符代码,字符串标题);

18休息;

19个案例'N':

20 case'n':

21 string NewRel(char code,string title);

22 break;

23案'M':

24案'm':

25字符串电影(字符代码,字符串标题);

26休息;

27默认值:

28 cout<<error<< endl;

29}

30返回0;

31}

32串电视(字符代码,字符串标题)

33 {

34浮动费用= 0;

35字符串类型=电视;

36返回类型;

37返回标题;

38退货成本;

39}

40字符串NewRel(字符代码,字符串标题)

41 {

42浮动成本= 6.99;

43 string type =New Release;

44 cout<<标题<< endl;

45 cout<<类型<< endl;

46 cout<< $<<成本<<结束;

47}

48字符串电影(字符代码,字符串标题)

49 {

50 int年 ;

51浮动费用;

52字符串类型=电影;

53 cout<< 输入电影年份<< endl;

54 cin>>年;

55 if(year< 1960)

56 {

57 cost = 2.99;

58 cout<<标题<< endl;

59 cout<<类型<< endl;

60 cout<< $<<成本<<结束;

61}

62否则如果(年< 1980)

63 {

64 cost = 3.99;

65 cout<<类型<< endl;

66 cout<< $<<成本<<结束;

67}

68否则如果(年< 2000)

69 {

70 cost = 4.99;

71 cout<<标题<< endl;

72 cout<<类型<< endl;

73 cout<< $<<成本<<如果(年> 2000)

76 {
5.99;

78 cout<<标题<< endl;

79 cout<<类型<< endl;

80 cout<< $<<成本<<结束;

81}

82其他

83 {

84 cout<< 2000年没有电影。 <<结束;

85}

86}



我的尝试:



我试过调整不同的部分。我试着查询我的问题,看看是否有其他人问过同样的事情。另外,抱歉我不知道如何输入数字,所以我只输入了它们。

解决方案

<<<<< endl ;

47}

48字符串电影(字符代码,字符串标题)

49 {

50 int year ;

51浮动费用;

52字符串类型=电影;

53 cout<<输入电影年份< ;< endl;

54 cin>>年;

55 if(year< 1960)

56 {

57成本= 2.99;

58 cout<< title<< endl;

59 cout<< type<< endl;

60 cout<<


<< cost<< endl;

61}

62 else if(year< 1980)

63 {

64 cost = 3.99;

65 cout << type<< endl;

66 cout<<


<< cost<< endl;

67}

68 else if(year< 2000)

69 {

70 cost = 4.99;

71 cout<<标题<< endl;

72 cout<<类型<< endl;

73 cout<<

I had to adjust my already working code to use functions. I tried to change things and it compiles, but when I input the code and title, nothing happens. There is no output.

1 */
2 #include <iostream>
3 using namespace std ;
4 int main()
5 {
6 string title ;
7 char code ;
8 int year ;
9 float cost ;
10 cout << "Enter the code of viewing and the title of the viewing. (Separated by a 11 space; either T, M, or N" << endl ;
12 cin >> code >> title ;
13 switch (code)
14 {
15 case 'T':
16 case 't':
17 string TV (char code, string title) ;
18 break ;
19 case 'N':
20 case'n':
21 string NewRel (char code, string title) ;
22 break ;
23 case 'M':
24 case 'm':
25 string Movie (char code, string title) ;
26 break ;
27 default:
28 cout << "error" << endl ;
29 }
30 return 0 ;
31 }
32 string TV (char code, string title)
33 {
34 float cost = 0 ;
35 string type = "TV" ;
36 return type ;
37 return title ;
38 return cost ;
39 }
40 string NewRel (char code, string title)
41 {
42 float cost = 6.99 ;
43 string type = "New Release" ;
44 cout << title << endl ;
45 cout << type << endl ;
46 cout << "$" << cost << endl ;
47 }
48 string Movie (char code, string title)
49 {
50 int year ;
51 float cost ;
52 string type = "Movie" ;
53 cout << "Enter year of movie" << endl ;
54 cin >> year ;
55 if (year < 1960 )
56 {
57 cost = 2.99 ;
58 cout << title << endl ;
59 cout << type << endl ;
60 cout << "$" << cost << endl ;
61 }
62 else if (year < 1980)
63 {
64 cost = 3.99 ;
65 cout << type << endl ;
66 cout << "$" << cost << endl ;
67 }
68 else if (year < 2000)
69 {
70 cost = 4.99 ;
71 cout << title << endl ;
72 cout << type << endl ;
73 cout << "$" << cost << endl ;
74 }
75 else if (year > 2000)
76 {
77 cost = 5.99 ;
78 cout << title << endl ;
79 cout << type << endl ;
80 cout << "$" << cost << endl ;
81 }
82 else
83 {
84 cout << "No movies from the year 2000." << endl;
85 }
86 }

What I have tried:

I have tried adjusting different parts. I tried to look up my question to see if anyone else has asked about the same thing. Also, sorry I didn't know how to enter this with the numbers, so I just typed them.

解决方案

" << cost << endl ;
47 }
48 string Movie (char code, string title)
49 {
50 int year ;
51 float cost ;
52 string type = "Movie" ;
53 cout << "Enter year of movie" << endl ;
54 cin >> year ;
55 if (year < 1960 )
56 {
57 cost = 2.99 ;
58 cout << title << endl ;
59 cout << type << endl ;
60 cout << "


" << cost << endl ;
61 }
62 else if (year < 1980)
63 {
64 cost = 3.99 ;
65 cout << type << endl ;
66 cout << "


" << cost << endl ;
67 }
68 else if (year < 2000)
69 {
70 cost = 4.99 ;
71 cout << title << endl ;
72 cout << type << endl ;
73 cout << "


这篇关于我的代码会要求输入,但不会给出输出。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆